有一个混乱的文件夹与我需要统一的ACL不一致。 我希望用PowerShell来实现这一点。 所以我试图search所有缺less所需组的文件,并将权限应用于Set-Acl:
Get-Acl | where {$_.accesstostring -notlike "*domain\required_grp*"} | Set-Acl $dir $acl
与icacls不同,Set-Acl要求您成为该文件的所有者,以便能够修改ACL。 这就是为什么:
$dir= Get-Acl .\reference_file $acl= $ACL.SetOwner([System.Security.Principal.NTAccount]$my_account)
那么,运行命令时,我得到以下错误:
Set-Acl : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:1 char:95
我很确定问题是输出到Set-Acl的输出格式,但不知道是什么。 感谢您的任何意见,非常感谢。
卢卡
我相信你会混淆PowerShell,因为你在pipe道中发送一个ACL数组,但是不要遍历每个ACL。 而且,Set-ACL CMDlet期望一条path沿着stream水线发送。
$acl= Get-Acl .\reference_file $acl= $ACL.SetOwner([System.Security.Principal.NTAccount]$my_account) Get-ChildItem | ? { (Get-ACL $_).accesstostring -notlike "*domain\groupname*"} | % { Set-ACL $_.Fullname $acl }
这对我有用。 它获取每个文件或文件夹,检查ACL是否与您的expression式匹配,并在需要时设置ACL。