无法使用PowerShell删除文件夹的权限

时间:2022-11-26 00:26:55

I'm using powershell to remove folder permissions. My code is something like this

我正在使用powershell删除文件夹权限。我的代码是这样的

$folder = "\\myServer\C$\myFolder";
$folder_acl = Get-Acl $folder;
$permission_toDelete = $folder_acl.Access | where{  <# selection operation #> }
$permission_toDelete | Foreach-Object { $folder_acl.RemoveAccessRule($_) }

This code return a lot of True, but it actually doesn't change permissions. The user I'm using is administrator on that server. I also tried to remove inheritance with this piece of code $folder_acl.SetAccessRuleProtection($true, $false); but still have the problem

这段代码返回了很多True,但它实际上并没有改变权限。我正在使用的用户是该服务器上的管理员。我还试图用这段代码删除继承$ folder_acl.SetAccessRuleProtection($ true,$ false);但仍然有问题

1 个解决方案

#1


3  

All that left is to pipe the current acl (after removal) to the Set-Acl cmdlet:

剩下的就是将当前的acl(删除后)传递给Set-Acl cmdlet:

$folder_acl | Set-Acl

All True output is the return value of each removed acl. You can suppress it if you want:

所有True输出都是每个删除的acl的返回值。你可以根据需要禁止它:

$folder_acl.RemoveAccessRule($_) | Out-Null

#1


3  

All that left is to pipe the current acl (after removal) to the Set-Acl cmdlet:

剩下的就是将当前的acl(删除后)传递给Set-Acl cmdlet:

$folder_acl | Set-Acl

All True output is the return value of each removed acl. You can suppress it if you want:

所有True输出都是每个删除的acl的返回值。你可以根据需要禁止它:

$folder_acl.RemoveAccessRule($_) | Out-Null