powershell - SetAccessRule - 部分或全部身份引用无法翻译
问题描述
我有一个在 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
解决方案
我最近在一个有许多域控制器分布在多个站点的环境中创建新的用户帐户和主目录时遇到了同样的挑战。我的解决方案是使用新创建帐户的 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
推荐阅读
- r - 如何在我们调用函数时返回多个对象并只显示部分返回
- swift - Swift 为 iOS 项目构建 IP 4 地址类
- r - 在shinyR中显示png文件
- c - 如何使用 rand() 函数生成以前未生成的不同数字?
- r - 使用 Rcpp 从 C 中获取矩阵/向量类型
- angular - 如何设置自定义对象的文本表示
- infragistics - IgGrid - 如何将自定义功能选择器连接到网格?
- python - 以相反的顺序配对两个列表
- php - 如何在 Ubuntu 上安装 Phar?
- android - 调用 MediaPlayer 的 stop 方法后无法再次启动 MediaPlayer