使用任何 .NET 框架
我能够创建安全组,但是当我尝试从同一域中添加用户时,出现错误。
使用System.DirectoryServices.AccountManagement
:
TheGroup = GroupPrincipal.FindByIdentity(SecurityContext, "GROUPNAME")
TheGroup.Members.Add(SecurityContext, IdentityType.SamAccountName, "username")
TheGroup.Save()
一切都适用于创建和获取现有组。添加成员也有效,但是当我尝试保存对组所做的更改时,我收到此错误:
Information about the domain could not be retrieved (1355).
现在不使用DirectoryServices.AccountManagement
就可以做到这一点:
Dim dGroup As DirectoryEntry = GetDirectoryEntry(GroupPath, UserName, Password)
dGroup.Properties("member").Add(nUser.Path)
dGroup.CommitChanges()
dGroup.Close()
再次以这种方式创建/删除组工作正常,但是当我尝试将确实存在的成员添加到创建的组中时,我收到此错误:
The server is unwilling to process the request. (Exception from HRESULT: 0x80072035)
进入运行 AD 本身的服务器,我可以添加组并将用户放入其中。我正在使用相同的凭据。
最佳答案
仅猜测:您可能会收到此错误,因为您尝试添加到安全组的用户没有遵循您的域密码策略的密码。
关于.net - 将用户添加到 Active Directory 中的安全组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/562585/