Search code examples
vbscriptactive-directoryadsi

Retrieve manager sAMAccountName for each user in AD VBscript


I need to get just the sAMAccountName of the manager not the fully distinguished name!

I am running this and got the distinguished name:

strUSRDAT_CTAMAN = objRecordSet.Fields("manager").Value

Solution

  • You should be able to get attribute values of an AD object via its distinguished name like this:

    dn  = "cn=foo,ou=bar,dc=dom,dc=example,dc=org"
    val = GetObject("LDAP://" & dn).Get("attr_name")
    

    In your case

    manager = GetObject("LDAP://" & strUSRDAT_CTAMAN).Get("sAMAccountName")