【发布时间】:2021-11-01 06:58:35
【问题描述】:
尝试将文件夹的所有者设置为域管理员并强制继承所有子文件夹/文件。使用我发现的脚本组合:
$Account = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList $DomainAdmins;
#Get a list of folders and files
$ItemList = Get-ChildItem -Path $Dir -Recurse;
#Iterate over files/folders
foreach ($Item in $ItemList) {
$Acl = $null; # Reset the $Acl variable to $null
$Acl = Get-Acl -Path $Item.FullName; # Get the ACL from the item
$Acl.SetOwner($Account); # Update the in-memory ACL
$isProtected = $false
$preserveInheritance = $false
$Acl.SetAccessRuleProtection($isProtected, $preserveInheritance)
Set-Acl -Path $Item.FullName -AclObject $Acl; # Set the updated ACL on the target item
}
Error: Set-Acl : Cannot bind argument to parameter 'AclObject' because it is null.
有些文件夹分配正确,但不是全部。我怀疑如果没有所有者(可能是从 AD 中删除的帐户)它会中断。
关于如何解决这个问题的任何想法?
【问题讨论】:
-
我建议查看NTFSSecurity 模块。这比使用内置 ACL 命令要容易得多。有一些文档here 和here。
-
谢谢。此时最好的猜测是目录中有长文件路径名。这可能会有所帮助。
-
是的,该模块使用了 Alphaleonis 库,该库可以绕过 Windows 对路径名限制的限制。
-
听起来不错。谢谢,我会告诉你情况如何。
标签: powershell active-directory