Search code examples
active-directoryldapldap-query

LDAP query to get account name from SID


So I have a SID of a FSP: S-1-5-21-2127521184-1604012920-1887927527-72713.

Translation worked in powershell but I would like to do the ldap query by myself, like here but have a little trouble with proper SID conversion.

Could you help me with query that give me a corresponding account name based on SID ?


Solution

  • You can bind directly to an object using the SID using LDAP://<SID=S-1-5-21-2127521184-1604012920-1887927527-72713>. Then get the username after that.

    In PowerShell, it would look something like:

    $account = [adsi]"LDAP://<SID=S-1-5-21-2127521184-1604012920-1887927527-72713>"
    $username = $account.Properties["sAMAccountName"]
    

    If the computer you run this from is on a different domain than the account, you may have to specify the domain:

    $account = [adsi]"LDAP://domain.com/<SID=S-1-5-21-2127521184-1604012920-1887927527-72713>"