如何通过SID获取(AD)LDAP人员条目?

鉴于用户或组的SID,我如何才能find属于它的LDAP对象?
LDAP服务器是Active Directory(Windows Server 2008)。

一个LDAP查询string将是有用的。

我希望它像以下一样简单:

dsget user“objectSID = {thesid},CN = Users,DC = domain,DC = com”-samid

但事实并非如此 AD将objectSID存储为hex。

虽然serverfault上的人写了一些可能有所帮助的答案:

使用SID从Active Directory中检索用户详细信息

另一种方法是放弃LDAP并使用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 

现在,如果您仍然需要,您可以通过LDAP轻松search多个属性。

我发现这个是旧的,但是你可以在ADUC中进行自定义search并点击高级选项卡。

LDAP查询string是:(objectSID = SID)

将“SID”replace为您正在查找的SID。

我必须使用以下代码在PowerShell中进行从SID到名称的翻译并返回到SID(对于外部安全主体):

 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 }