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