新しい Active Directory グループを作成したいと考えています。
これは私のコードです:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domain, container, userName, password);
GroupPrincipal oGroupPrincipal = new GroupPrincipal(ctx, userName);
DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, userName, password,AuthenticationTypes.Secure);
if (entry.Children.Find("CN=" + groupName) != null) {
}
if (!DirectoryEntry.Exists("LDAP://" + System.Configuration.ConfigurationManager.AppSettings["Domain"] + "/CN=" + groupName + "," + System.Configuration.ConfigurationManager.AppSettings["Container"]))
{
oGroupPrincipal.Description = groupName;
oGroupPrincipal.GroupScope = (System.DirectoryServices.AccountManagement.GroupScope)Enum.Parse(typeof(System.DirectoryServices.AccountManagement.GroupScope), groupScope);
oGroupPrincipal.IsSecurityGroup = isSecurity;
oGroupPrincipal.Save(ctx);
}
私が問題を抱えている部分は、新しく作成されたグループが作成される前に存在するかどうかを確認することです。この段階で、私のコードはすべてのグループが存在することを返すため、グループを作成できません
これは、グループが存在するかどうかを確認するためのものです:
if (entry.Children.Find("CN=" + groupName) != null) {
}
しかし、例外が発生しますサーバーにそのようなオブジェクトはありません。
任意の助けをいただければ幸いです。