Previous Section Table of Contents Next Section

The All-Purpose ADSI Object Query Script

Querying information is just as easy. Your script starts out with some generic object-retrieval code.


strContainer = ""

strName = "UserName"



'generic part

Set objRootDSE = GetObject("LDAP://rootDSE")

If strContainer = "" Then

  Set objItem = GetObject("LDAP://" & _

    objRootDSE.Get("defaultNamingContext"))

Else

  Set objItem = GetObject("LDAP://cn=" & strName & "," & _

   strContainer & "," & _

   objRootDSE.Get("defaultNamingContext"))

End If

Then, you add code depending on what type of object you're querying. For example, to get a user's name, just access objItem.Get("Name"). For the user's display name, it's just objItem.Get("displayName"). For an exhaustive list of properties of users, contacts, groups, computers, and organizational units, see the ADSI documentation, or just use the EZADScriptomatic, which you can download from www.microsoft.com/scripting.

    Previous Section Table of Contents Next Section