Recursively set permissions on folders using Powershell?

后端 未结 1 1549
鱼传尺愫
鱼传尺愫 2020-12-21 04:26

I have a directory which I want to go through recursively and set permissions on all the folders. So the order of operations should be:

  1. Remove all ACL from fo
相关标签:
1条回答
  • 2020-12-21 05:08

    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.

    0 讨论(0)
提交回复
热议问题