Update Folder Access
The code snippet is used to modify the permissions of an existing user or group that already has permissions on a folder. Here’s what the commands do:
- Set the variable
$Pathto the path of the folder whose permissions need to be modified. - Use the
Get-Aclcmdlet to get the access control list (ACL) of the folder and assign it to the$ACLvariable. - Use the
Where-Objectcmdlet to filter the access control entries (ACEs) in the$ACLvariable and find the one with anIdentityReferenceof"User1". - Set the
FileSystemRightsproperty of the ACE to"FullControl". - Use the
SetAccessRulemethod of the$ACLvariable to update the ACE with the modifiedFileSystemRightsvalue. - Use the
Set-Aclcmdlet to apply the modified ACL to the folder specified by the$Pathvariable.
In short, this code snippet modifies the permissions of a specific user or group that already has permissions on a folder.
# Modify permiison of existing IdentityReference (i.e. certain user/group whose permissions already exists on the folder)
$Path = "C:\MyFolder"
$ACL = Get-Acl $Path
$ACE = $ACL.Access | Where-Object {$_.IdentityReference -eq "User1"}
$ACE.FileSystemRights = "FullControl"
$ACL.SetAccessRule($ACE)
Set-Acl $Path $ACL