Recursively set permissions on folders using Powershell? Recursively set permissions on folders using Powershell? powershell powershell

Recursively set permissions on folders using Powershell?


Use SetAccessRuleProtection() to disable inheritance and remove inherited ACEs:

$acl.SetAccessRuleProtection($true, $false)

Use RemoveAccessRule() to remove existing (non-inherited) ACEs:

$acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) | Out-Null }

Use AddAccessRule() to add new ACEs:

$ace = New-Object Security.AccessControl.FileSystemAccessRule "user", ...$acl.AddAccessRule($ace)...

Do this only for the topmost folder. Leave inheritance enabled everywhere below, so your changes are propagated automatically.