Powershell: write permissions to subfolder

  • 1 year ago

1 / 1

To set write permissions to a subfolder using PowerShell, you can use the Set-Acl cmdlet. Here's an example:

$Acl = Get-Acl "C:\Path\To\Parent\Folder\Subfolder"
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("Users","Write","Allow")
Set-Acl "C:\Path\To\Parent\Folder\Subfolder" $Acl

In this example, replace C:\Path\To\Parent\Folder\Subfolder with the path to the subfolder you want to set write permissions for. The script first retrieves the Access Control List (ACL) for the subfolder using Get-Acl, and then creates a new Access Rule using the New-Object cmdlet. The FileSystemAccessRule constructor takes three parameters: the identity of the user or group to which the permission applies ("Users" in this case), the permission to grant ("Write" in this case), and the type of permission ("Allow" in this case).

The script then adds the new Access Rule to the ACL using the SetAccessRule method, and then sets the modified ACL back to the subfolder using Set-Acl.

Note that you may need to run PowerShell as an administrator in order to modify the ACL for a subfolder. Also, be careful when modifying ACLs, as incorrect settings can cause unintended behavior or security risks.