创建 AD 组时"Server is unwilling to process the request"



我试图创建一个Powershell脚本,在我的域控制器的用户容器下创建一个新组("TestUsers")。域控制器运行在2008 Server R2 64bit虚拟机上

我的代码是这样的:
#  Group Types in AD
#
# -2147483646 Global security group
# -2147483644 Domain local security group
# -2147483640 Universal security group
$groupName = "TestUsers"
$groupType = -2147483646
$root = [ADSI]""
$rootdn = $root.distinguishedName
$UsersNode = [ADSI]("LDAP://localhost:389/cn=Users,"+$rootdn)
$UsersNode.Create("group", "cn=" + $groupName)
$usersNode.Put("groupType", $groupType)    
$UsersNode.Put("sAMAccountName", $groupName)
$UsersNode.SetInfo()

执行$UsersNode.SetInfo()时,脚本抛出以下错误:

Exception calling "SetInfo" with "0" argument(s): "The server is unwilling to process the request.
"
At line:1 char:19
+ $UsersNode.SetInfo <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

我在域控制器上运行脚本,以域管理员帐户登录,即mydomain administrator

尝试了不同的组类型,但没有任何运气。

我是一个AD脚本的新手,所以我基本上遵循了下面的文章。

http://geekseat.wordpress.com/2011/02/10/script-of-the-day-creating-ad-groups-without-qad-cmdlets/

在上面的文章中,我不希望安装第三方cmdlet。

谢谢。

您忘记了组对象(这里是$CreatedGroup)是由用户节点中的创建返回的。您必须在组对象上添加属性。

解决方案如下:

#  Group Types in AD
#
# -2147483646 Global security group
# -2147483644 Domain local security group
# -2147483640 Universal security group
$groupName = "TestUsers"
$groupType = -2147483646
$root = [ADSI]""
$rootdn = $root.distinguishedName
$UsersNode = [ADSI]("LDAP://localhost:389/cn=Users,"+$rootdn)
$CreatedGrp = $UsersNode.Create("group", "cn=" + $groupName)
$CreatedGrp.Put("groupType", $groupType)  
$CreatedGrp.Put("sAMAccountName", $groupName)
$CreatedGrp.SetInfo()

请注意以管理员身份运行。


如果你使用的是Windows server 2008 R2,你可以使用ActiveDirectory模块中的Cmdlet(最短,更可读)

Import-Module ActiveDirectory
New-ADGroup -Name $groupName -SamAccountName $groupName -GroupCategory Security -GroupScope Global -DisplayName $groupName -Path "CN=Users" + $rootdn 

相关内容

最新更新