Jump to content

JPhillips173

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by JPhillips173

  1. 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 [email protected] System Admin Princeton Regional Schools
×
×
  • Create New...