Tuesday, December 14, 2010

Getting Manager and Direct Reports of an AD Account

If you ever needs to retrieve the manager and direct reports of an AD account, this vbscript snippet might come in handy.

Set objUser = GetObject(LDAP://cn=Bill,ou=Users,dc=deinfo,dc=net)

WScript.Echo "Title: " & objUser.title
WScript.Echo "Department: " & objUser.department
WScript.Echo "Company: " & objUser.company
WScript.Echo "Manager: " & objUser.manager
‘ this get the manager of the AD account

‘ directReports is multi-value so you need to loop through it to get all the values out
For Each strValue in objUser.directReports
WScript.Echo "Direct Reports: " & strValue
Next

Of course if you need to retrieve these information for a lot of accounts (e.g. all accounts within an OU or domain), you will need to query the OU or domain to and loop through all the accounts. I guess you get the idea.

No comments: