gpt4 book ai didi

c# - 获取 Active Directory 组的成员并检查他们是启用还是禁用

转载 作者:IT王子 更新时间:2023-10-29 04:36:49 25 4
gpt4 key购买 nike

获取给定 AD 组中所有成员/用户的列表并确定用户是否启用(或禁用)的最快方法是什么?

我们可能会谈论 20K 用户,所以我想避免为每个用户点击广告。

最佳答案

如果您使用的是 .NET 3.5 及更高版本,则应查看 System.DirectoryServices.AccountManagement (S.DS.AM) 命名空间。在这里阅读所有相关信息:

基本上,您可以定义域上下文并在 AD 中轻松找到用户和/或组:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

// if found....
if (group != null)
{
// iterate over members
foreach (Principal p in group.GetMembers())
{
Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);

// do whatever you need to do to those members
UserPrincipal theUser = p as UserPrincipal;

if(theUser != null)
{
if(theUser.IsAccountLockedOut())
{
...
}
else
{
...
}
}
}
}

新的 S.DS.AM 使得在 AD 中与用户和组一起玩真的很容易!

关于c# - 获取 Active Directory 组的成员并检查他们是启用还是禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7242226/

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