Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mass user deletion problem

Status
Not open for further replies.

gwilymb

MIS
Joined
Oct 31, 2006
Messages
3
Location
GB
I am trying to script a mass user deletion from a text file, and I can's seem to get it to work.I'm getting the error "An invalid AD pathname was passed" on line 29. Any ideas?


Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1
Const ForWriting = 2
Const DOMAIN = "DC=domain,DC=test"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("users.txt", ForReading)
Set objLogFile = objFSO.CreateTextFile("LogFile.txt", ForWriting)

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

strName = objFile.ReadLine
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://"& DOMAIN &"' WHERE objectCategory='user' AND sAMAccountName='" & strName & "' "
Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF
Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value)
objUser.Delete "user", "distinguishedName=" & objRecordSet.Fields("distinguishedName").Value

objRecordSet.MoveNext
Loop

objFile.Close

WScript.Echo "Finished
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top