On Error Resume Next
args = WScript.Arguments.Count
If args <> 1 Then
WScript.Echo "usage: delete_profiles SVRNAME"
WScript.Echo "example (for remote profiles): cscript.exe delete_profiles SOMESERVER "
WScript.Echo "example (for local profiles): cscript.exe delete_profiles . "
WScript.Quit
End If
strComputer = WScript.Arguments.Item(0)
Set objWMIService = GetObject("winmgmts:\\" & strComputer &"\root\cimv2")
Set colProfiles = objWMIService.ExecQuery("Select * from Win32_UserProfile")
Wscript.Echo "==" & WScript.Arguments.Item(0) & "==" & vbNewLine
For Each objProfile in colProfiles
Set objSID = objWMIService.Get("Win32_SID.SID='" & objProfile.SID &"'")
If (objSID.ReferencedDomainName = "DOMAIN NAME") Then
If Not ((objSID.AccountName = "USERNAME TO EXCLUDE") Or (Left (objSID.AccountName,2) = "USERNAME PREFIX TO EXCLUDE")) Then
Set objUserProfile = GetObject("winmgmts:{impersonationlevel=impersonate}!\\" _
& strComputer &"\root\cimv2:Win32_UserProfile." _
&"SID='" & objProfile.Sid &"'")
objUserProfile.Delete_
Wscript.Echo objSID.AccountName & ";" & objSID.ReferencedDomainName & ";" & objProfile.LocalPath & " - " & "DELETED"
End If
End If
Next
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (3)
Author
Commented:Regards,
Nik
Commented:
Input Error: There is no script engine for file extension ".vbs java".
Commented: