Finding a user's manager record in Active Directory

后端 未结 3 536
猫巷女王i
猫巷女王i 2021-01-15 05:12

Using Active Directory, am trying to find the SamAccountName and email of the user’s manager.

I find the logged on user in the AD by search where sAMAccountName = D

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-15 05:56

    (This is a post from old time, but I thought might be useful for others in the community)

    You can use string stripping and find it like this:

    REPLACE(SUBSTRING(manager, 4, CHARINDEX('OU=', manager)-5), '\', '')

    Full working query (just change DOMAIN to your own):

    SELECT Top 901 manager, REPLACE(SUBSTRING(manager, 4, CHARINDEX('OU=', 
    manager)-5), '\', '')
    FROM OPENQUERY( ADSI, 'SELECT manager FROM ''LDAP://DC=DOMAIN,DC=local'' 
         WHERE objectCategory = ''Person'' AND objectClass= ''user''
         AND userprincipalname = ''*'' AND mail = ''*'' AND SN = ''*'' ')
    

提交回复
热议问题