C# 在Active Directory中创建新组
我正在使用一个C#Windows应用程序。我想在该项目中实现Active Directory身份验证。但我不知道如何在Active Directory中创建组C# 在Active Directory中创建新组,c#,active-directory-group,C#,Active Directory Group,我正在使用一个C#Windows应用程序。我想在该项目中实现Active Directory身份验证。但我不知道如何在Active Directory中创建组 如何通过c#code在Active Directory中创建新组?如果您使用的是.NET 3.5及更高版本,您应该查看System.DirectoryServices.AccountManagement(S.DS.AM)命名空间。请在此处阅读所有相关内容: 基本上,您需要在要在其中创建组的容器上建立一个主体上下文,然后创建一个新的
如何通过c#code在Active Directory中创建新组?如果您使用的是.NET 3.5及更高版本,您应该查看
System.DirectoryServices.AccountManagement
(S.DS.AM)命名空间。请在此处阅读所有相关内容:
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使得在广告中与用户和群组进行互动变得非常容易