run LDAP query agains AD-domain?

  • Thread starter Stefan 'Birdie' Vogel
  • 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
 
W

Waydaws

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top