如何以编程方式将 AD 组添加到 SharePoint 2010 SPGroup?
尝试以编程方式将 AD 组添加到 SPGroup,但没有成功。
我已经尝试过:
SPGroup.AddUsers("myADgroup");
并且
SPGroupCollection.Add(groupName, currentUser, "myADgroup", groupDescription);
我已经尝试过使用域和不使用域。
有什么想法吗?
Been trying to add an AD group to an SPGroup programmatically and it's not working.
I've tried:
SPGroup.AddUsers("myADgroup");
and
SPGroupCollection.Add(groupName, currentUser, "myADgroup", groupDescription);
I've tried it both with domain and without.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
呃,没有 SPGroup.AddUsers("myAdGroup") 方法。甚至没有 AddUser()具有该格式的方法。
您是否尝试过:
EnsureUser 位确保AD 组已添加为 SPWeb 的用户,因此您可以分配权限。
Erm, there is no SPGroup.AddUsers("myAdGroup") method. There isn't even an AddUser() method with that format.
Have you tried:
The EnsureUser bit makes sure that the AD group is added as a user of the SPWeb, so you can then assign rights.
您好,目前没有添加 AD 组的方法。
您需要先创建组,然后将用户添加到该组。
Hi there is no methods for now to add AD group.
You need to create group first, aand after that add users to that group.
这是 Andy Burn 的回答的后续内容:
从 PowerShell 我最初尝试了以下操作:
这不起作用,这令人费解。
经过更多实验,我发现以下方法确实有效(Power Users 是内置组):
然后我注意到名称有不同的值(在 PowerShell 中别名为 DisplayName)——事实证明我使用了不同的值在 Active Directory 中查找“组名称”和“组名称(Windows 2000 之前的版本)”。
该组名称可以单独使用,但对于域前缀,我需要使用 Windows 2000 之前的名称。
有了这个,我能够完成以下工作:
因此,如果您仍然遇到问题,请检查 AD 中两个组名称之间的一致性。
This is a follow up from Andy Burn's answer:
From PowerShell I initially tried the following:
This didn't work, which was puzzling.
Some more experimentation and I found the following did work (Power Users is a built in group):
I then noticed that I had a different value for the Name (aliased as DisplayName in PowerShell) -- it turns out that I had used different values in Active Directory for 'Group name' and 'Group name (pre-Windows 2000)'.
The group name worked by itself, but with the domain prefix I needed to use the pre-Windows 2000 name.
With this, I was able to get the following to work:
So, if you are still having issues check for consistency between the two group names in AD.
我在使用 AD 组调用 SPWeb.EnsureUser 时也遇到了问题。就我而言,存在一些混乱,因为相关组的显示名称与其底层 sAMAccountName 不同。使用 sAMAccountName 而不是显示名称调用 EnsureUser 为我解决了问题。
I also experienced a problem with calling SPWeb.EnsureUser with an AD group. In my case there was some confusion because the group in question had a display name that was different to its underlying sAMAccountName. Calling EnsureUser with the sAMAccountName rather than the display name sorted the problem for me.