Hi all,
I'm trying to get the DN of a list of users from a text file. The script runs if i query Domain A using my domain account that resides on Domain A. But if i try to query Domain B using my same account on Domain A it says that the user doesn't exist. Although i can query users using my domain account via Active Directory Users and Computers.
Appreciate any inputs.
Const inFilename="c:\test\test.txt"
Const ForReading=1
strDomain = "dc=domain,dc=local"
strGroup = "CN=Group A,"
Set objFSO = CreateObject("scripting.filesystemobject")
Set objGroup = GetObject("LDAP://" & strGroup & "OU=My Groups," & strDomain)
Set inFile = objFSO.OpenTextFile(inFilename, ForReading, True)
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
While Not inFile.AtEndOfStream
strUserName=inFile.ReadLine
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://" & strDomain & ">;(&(objectCategory=User) (samAccountName=" & strUserName & "));distinguishedName;subtree"
Set objRecordSet = objCommand.Execute
If objRecordset.RecordCount = 0 Then
WScript.Echo strUserName & " does not exist in " & strDomain
Else
WScript.Echo strUserName & " exists!"
strDN = objRecordSet.Fields("DistinguishedName")
WScript.Echo strDN
End If
Wend
objConnection.Close
inFile.Close
I'm trying to get the DN of a list of users from a text file. The script runs if i query Domain A using my domain account that resides on Domain A. But if i try to query Domain B using my same account on Domain A it says that the user doesn't exist. Although i can query users using my domain account via Active Directory Users and Computers.
Appreciate any inputs.
Const inFilename="c:\test\test.txt"
Const ForReading=1
strDomain = "dc=domain,dc=local"
strGroup = "CN=Group A,"
Set objFSO = CreateObject("scripting.filesystemobject")
Set objGroup = GetObject("LDAP://" & strGroup & "OU=My Groups," & strDomain)
Set inFile = objFSO.OpenTextFile(inFilename, ForReading, True)
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
While Not inFile.AtEndOfStream
strUserName=inFile.ReadLine
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://" & strDomain & ">;(&(objectCategory=User) (samAccountName=" & strUserName & "));distinguishedName;subtree"
Set objRecordSet = objCommand.Execute
If objRecordset.RecordCount = 0 Then
WScript.Echo strUserName & " does not exist in " & strDomain
Else
WScript.Echo strUserName & " exists!"
strDN = objRecordSet.Fields("DistinguishedName")
WScript.Echo strDN
End If
Wend
objConnection.Close
inFile.Close