【发布时间】: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