gpt4 book ai didi

c# - 搜索只有 SID 的 AD

转载 作者:行者123 更新时间:2023-11-30 19:27:21 25 4
gpt4 key购买 nike

有没有办法使用仅具有 SID 的 UserPrincipal 搜索 Active Directory?我在 byte[] 中有 SID(之前使用 DirectorySearcher 查询)并使用 StringBuilder 将其转换为“S-1-15-...”和“\01\05..”。

我试过这样处理:

PrincipalContext pContext = new PrincipalContext(ContextType.Domain);
UserPrincipal pUser = new UserPrincipal(pContext);
pUser.Sid = stringBuilder.ToString();
PrincipalSearcher pSearcher = new PrincipalSearcher();
pSearcher.QueryFilter = pUser;
Console.WriteLine(pSearcher.FindOne().DistinguishedName.ToString());

Visual Studio 告诉我,Sid 是写保护的。当然……

提前致谢并干杯亚历克斯

p.s.:我已经尝试按照这里描述的方式解决它:How can I convert from a SID to an account name in C# , 但这里没有成功。

最佳答案

当然可以。我使用以下方法在名为“Atlas”的内部应用程序中查找我的用户。请原谅格式化。

using (var context = new PrincipalContext(ContextType.Domain, "DOMAIN_NAME_IMPORTANT"))
{
var userIdentity = UserPrincipal.FindByIdentity(context, "USER GUID GOES HERE"));
}

关于c# - 搜索只有 SID 的 AD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18852323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com