run LDAP query agains AD-domain?

  • Thread starter Thread starter Stefan 'Birdie' Vogel
  • Start date Start date
S

Stefan 'Birdie' Vogel

Hello,

I need to run a query agains a 2003-ActiveDirectory using LDAP.
It works fine for the domain I'm logged in, but I need to run it agains a
different domain in our forrest.
Just want to avoid to login to each of our domains for running the script.


strField = "distinguishedName"
'Create ADO connection object for Active Directory
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"

'Create ADO command object for the connection.
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConn

'Get the ADsPath for the domain to search.
Set objRoot = GetObject("LDAP://rootDSE")
strDomain = objRoot.Get("defaultNamingContext")
Set objDomain = GetObject("LDAP://" & strDomain)


strSQL = "SELECT " & strField & " FROM '"
strSQL = strSQL & "LDAP://" & strDomain & "' WHERE samaccountname = '" &
Shortname & "'"




Regards
Stefan
 
Hello,

I need to run a query agains a 2003-ActiveDirectory using LDAP.
It works fine for the domain I'm logged in, but I need to run it agains a
different domain in our forrest.
Just want to avoid to login to each of our domains for running the script.

strField = "distinguishedName"
'Create ADO connection object for Active Directory
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"

'Create ADO command object for the connection.
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConn

'Get the ADsPath for the domain to search.
Set objRoot = GetObject("LDAP://rootDSE")
strDomain = objRoot.Get("defaultNamingContext")
Set objDomain = GetObject("LDAP://" & strDomain)

strSQL = "SELECT " & strField & " FROM '"
strSQL = strSQL & "LDAP://" & strDomain & "' WHERE samaccountname = '" &
Shortname & "'"

Regards
Stefan

What does,

strRootDomain = "LDAP://" & objRootDSE.Get("rootDomainNamingContext")
WScript.Echo "ADsPath to root domain container: " & strDomain
Set objRootDomain = GetObject(strRootDomain)
WScript.Echo "Current Domain Object:"
WScript.Echo "Name: " & objRootDomain.Name
WScript.Echo "Class: " & objRootDomain.Class & VbCrLf

give you? It should be the Root Domain, as opposed to your default
Domain. (It could also be the same.)
 
Back
Top