我扩展了martona的代码片段,并且能够访问所有文件夹和子文件夹.这是我的代码 –
$FilesAndFolders = gci "c:\data" -recurse | % {$_.FullName} foreach($FileAndFolder in $FilesAndFolders) { #using get-item instead because some of the folders have '[' or ']' character and Powershell throws exception trying to do a get-acl or set-acl on them. $item = gi -literalpath $FileAndFolder $acl = $item.GetAccessControl() $permission = "Everyone","FullControl","Allow" $rule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission $acl.SetAccessRule($rule) $item.SetAccessControl($acl) }