【发布时间】:2016-05-14 09:53:18
【问题描述】:
我试图弄清楚为什么在 powershell 中调用 Set-Acl 失败。
该调用是用于设置 AD OU 的较大脚本的一部分。该脚本的基本步骤是:
- 创建一个新的 OU
- 向该 OU 添加组
- 在文件共享上创建一个文件夹。
- 将新创建的组的权限添加到新创建的文件夹。
- 将模板文件夹的内容复制到新文件夹中。
- 创建一个 DFS 文件夹以指向新文件夹。
脚本工作很好除了调用SetACL:
#Some initialization data. In reality, the exact values are generated using the script parameters.
$NewDataPath="\\server\share\folder\"
$NewGroupName="UserGroup_1234"
#The actual code from the original script
$Acl = Get-Acl $NewDataPath
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($NewGroupName, "Modify", "ContainerInherit,ObjectInherit", "None", "Allow")
#exception happens on the following line
$Acl.SetAccessRule($Ar)
#whetever happens afterward works fine
Set-Acl -Path $NewDataPath $Acl
这会引发以下异常:
Exception calling "SetAccessRule" with "1" argument(s): "Some or all
identity references could not be translated."
+ $Acl.SetAccessRule <<<< ($Ar)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
真正奇怪的是,如果我手动运行每一行,它就可以工作。我已将代码移动到一个单独的函数中,并在初始代码失败后手动调用它(使用完全相同的参数)也可以。
更奇怪的是:如果我在将数据复制到其中之后移动更新权限的代码部分,它会起作用。
就好像 SetAccessRule 方法调用(或者可能是 FileSystemAccessRule 对象)无法访问 AD 中的新数据,即使所有其他调用工作正常并且如果引入了轻微的延迟,它也会恢复。
虽然我能够找到解决方法,但我真的很想了解这里发生了什么。
【问题讨论】:
-
也许您可以通过提供唯一标识符(如 objectGUID、SID 或 DN)而不是您刚刚创建的组的名称来帮助解决身份参考。
$newGroup = New-ADGroup UserGroup_1234 -PassThru; ... ; New-Object FileSystemAccessRule($newGroup.SID,"Modify", ...) -
奇怪的是,这行得通。我仍然想知道根本原因是什么,但是,如果您将该评论作为答案,我会接受它
标签: windows powershell powershell-2.0 windows-server-2008-r2