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
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