Given the SID of a user or a group, how can I find a LDAP object that belongs to it?
LDAP Server ist Active Directory (Windows Server 2008).
A LDAP query String would be useful.
Given the SID of a user or a group, how can I find a LDAP object that belongs to it?
LDAP Server ist Active Directory (Windows Server 2008).
A LDAP query String would be useful.
Another way would be to forsake LDAP and use WMIC:
H:\>wmic useraccount where (sid = "S-1-5-21-1698188384-1693678267-1543859470-6637") get * /format:list
AccountType=512
Caption=MYDOMAIN\quux
Description=some guy's account
Disabled=FALSE
Domain=MYDOMAIN
FullName=Some Guy
InstallDate=
LocalAccount=FALSE
Lockout=FALSE
Name=quux
PasswordChangeable=TRUE
PasswordExpires=FALSE
PasswordRequired=TRUE
SID=S-1-5-21-1698188384-1693678267-1543859470-6637
SIDType=1
Status=OK
Now you have several attributes that should be easy to search via LDAP, if you still need to.
I wish it was as easy as:
dsget user "objectSID={thesid},CN=Users,DC=domain,DC=com" -samid
But it's not; AD stores the objectSID as hexadecimal.
The folks on serverfault have written a few answers that may help, though:
I see this one is old, but you can do this in ADUC by going to Custom Search and clicking on the advanced tab.
LDAP query string is: (objectSID=SID)
Replace "SID" with the SID that you're looking for.
I've had to do translations from SID to name and back to SID (for foreign security principals) in PowerShell using the following code:
function Find_By_SID($SID) {
//Searches Active Directory by SID
//Returns NetBios Name
// Example output: CONTOSO\User1
$account = New-Object Security.Principal.SecurityIdentifier("$SID")
$netbios = $account.Translate([Security.Principal.NTAccount])
return $netbios.Value
}
It is to search by SID using an LDAP query. For example:
dsquery * domainroot -filter "(objectSid=S-1-5-21-blah-blah-blah-500)"
or, in PowerShell,
Get-ADuser -LDAPFilter '(objectSid=S-1-5-21-blah-blah-blah-500)'
will get the domain Administrator account, if you sub in your domain value for blah-blah-blah
.