【问题标题】:"Server is unwilling to process the request" when creating an AD group创建 AD 组时“服务器不愿意处理请求”
【发布时间】:2011-07-18 20:00:37
【问题描述】:

我正在尝试创建一个 Powershell 脚本以在我的域控制器中的用户容器下创建一个新组(“TestUsers”)。域控制器在 2008 Server R2 64 位 VM 上运行。

我的代码是这样的:

#  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/

如上文所述,我不想安装第 3 方 cmdlet。

谢谢。

【问题讨论】:

  • 根据 JP 所说,您可能需要调整脚本,但我想对(有点情绪化!)错误消息“服务器不愿意处理请求”说点什么。我曾经间歇性地得到它,这是一个临时问题,重试脚本\操作会起作用。我们认为这可能与复制有关,但从未深入了解问题的根源。有时似乎 AD 会忽略我们! :-)
  • 我随身携带一根带钉子的棍子,用于不情愿的计算机...

标签: powershell active-directory


【解决方案1】:

您只是忘记了用户节点中的创建返回了组对象(此处为$CreatedGroup)。您必须在 groupe 对象上添加属性。

解决办法如下:

#  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 

【讨论】:

    猜你喜欢
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    相关资源
    最近更新 更多