我有一些代码DirectoryEntry
用于通过 LDAP 操作本地 Active Directory。目前我找到一个特定的OU
,添加一个用户,更新用户的属性,然后提交所有更改:
DirectoryEntry ldapRoot = new DirectoryEntry(ldapString, user, password);
DirectoryEntry userGroup = ldapRoot.Children.Find("OU=OUGroup");
DirectoryEntry newUser = userGroup.Children.Add("CN=" + userName, "user");
newUser.Properties["displayName"].Value = displayName;
...
newUser.CommitChanges();
userGroup.Close();
ldapRoot.Close();
ldapString 类似于LDAP:\\DC=company,DC=local
,基本上它只是获取根条目。
我更改了几个属性,但一切正常。但是,我有另一个OU
名为 SharePoint_Groups,其中有一个名为Internal
. 我想将新用户添加为该组的成员,但我不知道该怎么做。我尝试了以下方法:
DirectoryEntry spGroup = ldapRoot.Children.Find("OU=Sharepoint_Groups");
DirectoryEntry internal = spGroup.Children.Find("CN=Internal");
它不起作用,我不确定我应该如何解决Internal
- CN= 正确还是应该使用其他规范?
而且,一旦我有了正确的组,如何将现有用户添加到其中?
提前致谢