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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to query DN on a different domain

Status
Not open for further replies.

mvvilleza

MIS
Nov 23, 2000
114
PH
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top