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

Get full AD path to a group 1

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
GB
Hi

If I have the name of a group, how can I pull out the full AD/LDAP path?

e.g.
Code:
DEPT_IT
to
Code:
CN=DEPT_IT,CN=Users,DC=acme,DC=com

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Code:
  Set oRoot = GetObject("LDAP://rootDSE")
  sDomainPath = oRoot.Get("defaultNamingContext")

  Set oConnection = CreateObject("ADODB.Connection")
  oConnection.Provider = "ADsDSOObject"
  oConnection.Open "Active Directory Provider"

  sGroup = "DEPT_IT"

  Set oRs = oConnection.Execute("SELECT adspath " & _
                                "FROM 'LDAP://" & sDomainPath & "'" & _
              			"WHERE objectCategory='group' AND " & _
                                "Name='" & sGroup & "'")

  If Not oRs.EOF Then
   sAdsPath = oRs("adspath")
   msgbox(sAdspath)   
  Else
   msgbox("Not in AD")
  End If
 
And that's so simple.

Yet, well, maybe it's the search criteria I was using in Google because I couldn't find that info anywhere.

Thank you, bslintx. Have a star (even though I've not tested it yet)!

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top