Convert-SidToADObject will take an AD SID and return an object containing the object’s name, SamAccountName, Description, type and distinguished name.
function Convert-SidToADObject($sid) { $u = [adsi]("LDAP://<SID=" + $sid + ">") if ($u.SamAccountName) { [psCustomObject]@{ Name = $u.Name.value SamAccountName = $u.samAccountName.value Description = $u.description.value Type = $u.objectclass.Value[1] DistinguishedName = $u.distinguishedName.value } } Else { "Lookup Failed" } }
This function shows the relatively obscure binding string for SIDs in AD. It uses the ADSI accelerator, so it doesn’t require the ActiveDirectory module.