Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell remove all permissions on a folder for a specific user

I need a script or simple powershell code for removing all permissions to a folder for specific user, by inheriting these deletion to all the subfolders and files as well - recursively... Thank you in advance!

like image 1000
gaponte69 Avatar asked Nov 22 '12 13:11

gaponte69


People also ask

What removes all rules for a certain user in PowerShell?

The RemoveAccessRule method removes either all matching Deny access rules or all matching Allow access rules from the current FileSystemSecurity object.

How do I Remove user folder permissions?

Hover over the desired shared folder and click Sharing. Locate the user and click on the Permissions button. Select the appropriate permission settings for the user. To remove access, click Remove member.

How do I turn off Acl permissions in PowerShell?

To remove an ACL entry, create a new ACL object for ACL entry to be removed, and then use that object in remove ACL operation. Do not get the existing ACL, just provide the ACL entries to be removed. Remove ACL entries by using the Remove-AzDataLakeGen2AclRecursive cmdlet.


1 Answers

 $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

like image 116
Loïc MICHEL Avatar answered Sep 26 '22 16:09

Loïc MICHEL