Pumaedition Posted April 22, 2008 Posted April 22, 2008 Hi, I am after a script (am useless at writing them myself!) that will allow me to delete profiles that have been created in the "C:\Documents and Settings" folder, but will leave ones that are needed (Administrator, Default User, All Users) Need this by Thursday (no students in due to NUT strike), and doing it automagically will be a lot easier than manually having to do it on around 300 computers Many Thanks Matt
Pumaedition Posted April 22, 2008 Author Posted April 22, 2008 amazing what a frantic search can bring Got a VBS script that works now, so all is sweet. Takes a little time, but it does it
browolf Posted April 22, 2008 Posted April 22, 2008 (edited) if your computers have suitably organised names, you can use delprof* c:\>for /f %a in ('net view ^| find "prefix" /I ') do delprof /c:%a /q /i replace prefix with whatever otherwise you can use ' The following script will enumerate all computer accounts ' within an Active Directory domain Const ADS_SCOPE_SUBTREE = 2 strDomain = "domainname" Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCOmmand.ActiveConnection = objConnection objCommand.CommandText = _ "Select Name, Location from 'LDAP://" & strDomain & "' " _ & "Where objectCategory='computer'" objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF Wscript.Echo objRecordSet.Fields("Name").Value 'Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value objRecordSet.MoveNext Loop to get a list of computers from the domain. forward it into a file ie c:\>cscript filename.vbs >> list.txt import file into excel sort and remove any u dont want to touch, laptops, servers etc save as a csv file then do c:\>for /f %a in ('type list.csv') do delprof /c:%a /q /i *deprof is specifically for deleting user profiles and will leave the other ones, you can download it at Download details: User Profile Deletion Utility (Delprof.exe) edit: oh you found one whilst i was writing this Edited April 22, 2008 by browolf updated 1
srochford Posted April 22, 2008 Posted April 22, 2008 Add your stuff to the machine startup script and then it will run at each startup and keep things tidy!
FN-GM Posted April 22, 2008 Posted April 22, 2008 You can use this VBS Script Function Main() On Error Resume Next Dim obtainfolder Dim Pathfinder Dim strPath Set fso = CreateObject("Scripting.FileSystemObject") strPath = "C:\Documents and Settings\" set excludefile = fso.OpenTextFile("\\Server\SYSVOL\doamin.local\scripts\cleanprofiles\exclude.txt", 1) excludelist = excludefile.Readall 'msgbox excludelist Set f = fso.GetFolder(strPath) ' Loop through all subfolders For Each fldrItem in f.SubFolders fldrName = fldrItem.name If Right(strPath,1) <> "\" Then Pathfinder = strPath & "\" & fldrName Else Pathfinder = strPath & fldrName End If If InStr(1, excludelist, fldrName, 1) Then 'msgbox "Has not deleted " & fldrName Else 'msgbox "Deleting " & fldrName set obtainfolder = fso.GetFolder(Pathfinder) obtainfolder.Delete true End If 'End Select Next ' Clean up objects Set fso = Nothing Set fc = Nothing End Function call Main() make a text file and call it exclude.txt, then add the names of folders you dont want deleting such as default user & all users. Then alter the path of where it is located in the script. Hope this helps Z
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now