gpt4 book ai didi

c# - 在 Active Directory 中创建新组

转载 作者:太空宇宙 更新时间:2023-11-03 10:45:04 25 4
gpt4 key购买 nike

我正在使用 C# Windows 应用程序。我想在该项目中实现 Active Directory 身份验证。但我不知道如何在 Active Directory 中创建组。

如何通过 C# 代码在 Active Directory 中创建新组?

最佳答案

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

基本上,您需要在要在其中创建组的容器上建立一个principal context,然后创建一个新的GroupPrincipal,设置它的属性,并保存:

// set up domain context and binding to the OU=TechWriters organizational unit in your company
using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YourCompany", "ou=TechWriters,dc=yourcompany,dc=com"))
{
// create a new group principal, give it a name
GroupPrincipal group = new GroupPrincipal(ctx, "Group01");

// optionally set additional properties on the newly created group here....

// save the group
group.Save();
}

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

关于c# - 在 Active Directory 中创建新组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23778043/

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