[dba-Tech] Bit of scripting help?

Jon Tydda jon.tydda at lonza.com
Mon Apr 27 10:44:14 CDT 2015


Hi all

I'm trying to automate a long and tedious process with some batch files, and I've hit a stumbling block.

Every month I have a list of users who have left, and after their accounts have been closed down, I need to remove their home folders from the server.

We have three locations where someone's folder could be; Home-S, Home-M and Home-L (small, medium and large).

I've got a script that runs through one of these folders and changes the ownership of the relevant username's files and folders, and then deletes the main folder, but if the username isn't in the Small folder (for example), it then starts changing permissions to another random user's files and folders. What I'd like it do to is to realise that the folder doesn't exist, and instead search the Medium (and then Large) folder, or skip it entirely.

Here's my code - what am I missing?

for /F %%f in (Dellist.txt) do (takeown /f \\SERVER\home-s\%%f /r /d y)
for /F %%f in (Dellist.txt) do (icacls \\ SERVER\home-s\%%f /inheritance:r /grant administrators:F /t /c)
for /F %%f in (Dellist.txt) do (takeown /f \\ SERVER\home-s\%%f\*.* /r /d y)
for /F %%f in (Dellist.txt) do (icacls \\ SERVER\home-s\%%f\*.* /inheritance:r /grant administrators:F /t /c)

for /F %%f in (Dellist.txt) do (call cmd.exe /C "rd \\uksfs01\home$\home-s\%%f" /S)

Thanks


Jon

________________________________
This communication and its attachments, if any, may contain confidential and privileged information the use of which by other persons or entities than the intended recipient is prohibited. If you receive this transmission in error, please contact the sender immediately and delete the material from your system.


More information about the dba-Tech mailing list