简体   繁体   English

powershell 删除特定用户对文件夹的所有权限

[英]powershell remove all permissions on a folder for a specific user

我需要一个脚本或简单的 powershell 代码来删除特定用户对文件夹的所有权限,方法是将这些删除继承到所有子文件夹和文件 - 递归......提前谢谢!

 $acl=get-acl c:\temp
 $accessrule = New-Object system.security.AccessControl.FileSystemAccessRule("domain\user","Read",,,"Allow")
 $acl.RemoveAccessRuleAll($accessrule)
 Set-Acl -Path "c:\temp" -AclObject $acl

this should wipe all security rules for user in c:\\temp recursively这应该以递归方式擦除 c:\\temp 中用户的所有安全规则

i think the simpler way to do this is to copy acl from a file or folder that have the correct permissions and apply it to the folder where you want specific access.我认为更简单的方法是从具有正确权限的文件或文件夹中复制 acl 并将其应用于您想要特定访问权限的文件夹。 example:例子:

$acl= get-acl /path/to/file_with_correct acl 
$files = get-childItem c:\temp\*.* -recurce | set-acl -aclobject $acl -whatif

remove the -whatif parameter to effectively modify acl删除 -whatif 参数以有效修改 acl

Or follow this technet article and use a code like :或者按照这篇技术网文章并使用如下代码:

$Right = [System.Security.AccessControl.FileSystemRights]::Read
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None 
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly  
$objType = [System.Security.AccessControl.AccessControlType]::Allow 

$objUser = New-Object System.Security.Principal.NTAccount("domain\bob") 
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
    ($objUser, $Right, $InheritanceFlag, $PropagationFlag, $objType) 
$objACL = Get-ACL "d:\test" 
$objACL.RemoveAccessRuleAll($objACE) 
Set-ACL "d:\test" -AclObject $objACL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM