gpt4 book ai didi

c# - 使用 C# 创建 Active Directory 组

转载 作者:行者123 更新时间:2023-11-30 16:17:23 25 4
gpt4 key购买 nike

我正在创建一个用于管理 Active Directory 的 Web 应用程序。我想在某个容器中创建一个组。

var groups = new List<Models.Group>();

PrincipalContext ctx =
new PrincipalContext(ContextType.Domain, domain, container, userName, password);

GroupPrincipal oGroupPrincipal = new GroupPrincipal(ctx);
oGroupPrincipal.Description = mGroup.GroupName;
oGroupPrincipal.GroupScope = mGroup.GroupScope;
oGroupPrincipal.IsSecurityGroup = mGroup.IsSecurity;
oGroupPrincipal.Save();

但我收到以下错误:

Cannot implicitly convert type 'string' to System.DirectoryServices.AccountManagement.GroupScope?'

我不知道该如何处理。我应该如何将 GroupScope 转换为对象 GroupScope,而它是我列表中的对象字符串?

我也遇到了这个错误:

SamAccountName or Name must be assigned to a newly-created Principal object in this store > prior to saving.

最佳答案

组作用域是一个枚举,具有本地、全局和通用值,看起来您还没有转换传入值。

尝试将其设置为静态值:

oGroupPrincipal.GroupScope = System.DirectoryServices.AccountManagement.GroupScope.Local;

如果这清除了错误,则尝试解析您传入的字符串:

oGroupPrincipal.GroupScope = (System.DirectoryServices.AccountManagement.GroupScope)Enum.Parse(typeof(System.DirectoryServices.AccountManagement.GroupScope),value);

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

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