Hey guys,
This one should get the juices flowing. Here's what i need.
I need a script that will go into a shared folder where all our students home folders are and delete a folder and all it's sub-folders inside of each users home folder. So it will have to support wildcards because i can't put a line of code for each 1200 students. Also it has to run on a windows 2003 server, and be able to be called automatically before our backup jobs run every night.
Here's the path:
e:\students\(usernames)\library\caches
e:\students\(username)\library\application support\firefox\profiles
(username) being the wildcard so it will parse every folder and find the sub-folders and delete them.
Also last year i started grouping the home folders by graduation year to make it easier to remove once they graduate, so there is also a sub-folder that has all of the sophmore home folders in it.
Here's it's path:
e:\students\2010\(username)\library\caches
e:\students\2010\(username)\library\application support\firefox\profiles
I know this is a complicated script and i found one from the windows "scripting guys" but i don't know if it will do wildcards and if it does what they are. (maybe *)
Here's the script they gave me:
--------------------------------------------------------
Dim arrFolders()
intSize = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
strFolderName = "c:\scripts\archive"
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
ReDim Preserve arrFolders(intSize)
arrFolders(intSize) = strFolderName
intSize = intSize + 1
For Each objFolder in colSubfolders
GetSubFolders strFolderName
Next
Sub GetSubFolders(strFolderName)
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder2 in colSubfolders2
strFolderName = objFolder2.Name
ReDim Preserve arrFolders(intSize)
arrFolders(intSize) = strFolderName
intSize = intSize + 1
GetSubFolders strFolderName
Next
End Sub
For i = Ubound(arrFolders) to 0 Step -1
strFolder = arrFolders(i)
strFolder = Replace(strFolder, "\", "\\")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name = '" & strFolder & "'")
For Each objFolder in colFolders
errResults = objFolder.Delete
Next
Next
-------------------------------------------------------------------------
I know this is complicated script but they said that the script must delete all of the sub-folders before it will delete the root folder.
If i've left out any important info let me know.
Thanks for the help,
Jon Phillips
JPhillips@monet.prs.k12.nj.us
System Admin
Princeton Regional Schools
Wow!
Might not need to be that difficult - sometimes batch files are easier ...
e:
cd \students
for /d %%i in (*) do rd "e:\students\%%i\library\caches" /s /q
for /d %%i in (*) do rd "e:\students\%%i\application support\firefox\profiles" /s /q
Not sure if you want to delete the contents of each folder but leave the folder - if so, it's probably easier to just delete the folder and its contents and then put back an empty folder:
for /d %%i in (*) do md "e:\students\%%i\library\caches"
for /d %%i in (*) do md "e:\students\%%i\application support\firefox\profiles"
I'll dig out some vbscript later but my tea's ready now :-)
Don't mean to hijack here but I would like a slight modification to this script as I need to copy a couple of folders into every users home directory, don't know how to set up the (*) wildcard properly though, any help appreciated.
There are currently 1 users browsing this thread. (0 members and 1 guests)