我想将 SID 的 System.Byte[] 类型转换为字符串。
我的代码:
string path = "LDAP://DC=abc,DC=contoso,DC=com";
DirectoryEntry entry = new DirectoryEntry(path);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectClass=user)(samaccountname=user1))";
results = mySearcher.FindAll();
foreach (SearchResult searchResult in results)
{
Console.WriteLine(searchResult.Properties["ObjectSID"][0].ToString());
}
我尝试了这个,但它从我当前登录的域中获取值,并且我需要来自给定域的值。
System.Security.Principal.NTAccount(user1)
.Translate([System.Security.Principal.SecurityIdentifier]).value