【问题标题】:SetAccessRule - Some or all Identity references could not be translatedSetAccessRule - 部分或全部身份引用无法翻译
【发布时间】:2019-02-20 13:13:21
【问题描述】:

我有一个在 Active Directory 中创建目录和组的脚本。只有组中的用户才能访问该目录。大多数时候它工作得很好,没有任何问题,但有时我得到一个异常,我不知道为什么。任何想法是什么问题?

我的代码:

[...]

New-ADGroup -Server $adserver -Path $adpath -Description $description -Name $groupname -GroupScope DomainLocal -GroupCategory Security
New-Item -Path $dirpath -Name "$dirname" -ItemType "directory"

Start-Sleep -s 30     #wait to make sure directory is created

$dp = "$dirpath\$dirname"

$Acl = Get-Acl $dp

#fileradmingroup
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($admingroup,"FullControl","ContainerInherit,ObjectInherit","None","Allow")
$Acl.SetAccessRule($Ar) 
Set-Acl $dp $Acl

#remove inherited permissions
$Acl.SetAccessRuleProtection($true,$false) 
Set-Acl -Path $dp -AclObject

#new created group $groupname
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($groupname,"DeleteSubdirectoriesAndFiles, Write, ReadAndExecute, Synchronize","ContainerInherit,ObjectInherit","None","Allow")
$Acl.SetAccessRule($Ar)     #this is the line where the exception occurs
Set-Acl $dp $Acl

[...]

这里是例外:

使用“1”参数调用“SetAccessRule”的异常:“部分或全部身份 无法翻译参考文献。” 在 L:\Skripte\Skript2.ps1:178 char:9 + $Acl.SetAccessRule($Ar) + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : IdentityNotMappedException

【问题讨论】:

  • 组创建是否可能没有复制到文件服务器使用的域控制器?
  • @AdminOfThings 如果脚本正常工作,新目录的权限包含一个 SID 号。一段时间后(我认为大约半小时),SID 变成了新组的名称。所以我认为这不会是一个问题?
  • 如果完全收敛需要 30 分钟,那么从创建组开始,您只需等待 30 秒。使用存储在您的 $adserver 变量中的 AD 服务器手动创建一个新的 AD 组。登录到包含您要配置的文件共享的服务器。查看尝试将组添加到文件共享时从服务器在 AD 中找到组需要多长时间。如果该组出现的时间不同,那么这就是您的问题的一部分。
  • 好的,我试试这个。谢谢。

标签: powershell active-directory acl identity


【解决方案1】:

我最近在一个有许多域控制器分布在多个站点的环境中创建新用户帐户和主目录时遇到了同样的挑战。我的解决方案是使用新创建帐户的 sid。

我更改了创建组的行和创建访问规则的行。 Start-Sleep 应该不需要并被注释掉。

我希望它适用于您的情况。

$NewGroup = New-ADGroup -Server $adserver -Path $adpath -Description $description -Name $groupname -GroupScope DomainLocal -GroupCategory Security -PassThru
New-Item -Path $dirpath -Name "$dirname" -ItemType "directory"

#Start-Sleep -s 30     #wait to make sure directory is created

$dp = "$dirpath\$dirname"

$Acl = Get-Acl $dp

#fileradmingroup
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($admingroup,"FullControl","ContainerInherit,ObjectInherit","None","Allow")
$Acl.SetAccessRule($Ar) 
Set-Acl $dp $Acl

#remove inherited permissions
$Acl.SetAccessRuleProtection($true,$false) 
Set-Acl -Path $dp -AclObject

#new created group $groupname
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($NewGroup.SID,"DeleteSubdirectoriesAndFiles, Write, ReadAndExecute, Synchronize","ContainerInherit,ObjectInherit","None","Allow")
$Acl.SetAccessRule($Ar)     #this is the line where the exception occurs
Set-Acl $dp $Acl

【讨论】:

  • 这个解决方案效果很好。我在一天中已经对其进行了多次测试,但我不再得到异常。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-11
  • 2012-07-16
  • 2017-04-10
  • 1970-01-01
相关资源
最近更新 更多