PowerShell To Set Folder Permissions

前端 未结 5 839
旧时难觅i
旧时难觅i 2020-12-05 12:35

I am trying to use the \"default\" options in applying folder permissions; by that, I mean that using the \"Full Controll, Write, Read, etc\" in the \'Properties\' for a fol

5条回答
  •  天涯浪人
    2020-12-05 13:33

    In case you had to deal with a lot of subfolders contatining subfolders and other recursive stuff. Small improvment of @Mike L'Angelo:

    $mypath = "path_to_folder"
    $myacl = Get-Acl $mypath
    $myaclentry = "username","FullControl","Allow"
    $myaccessrule = New-Object System.Security.AccessControl.FileSystemAccessRule($myaclentry)
    $myacl.SetAccessRule($myaccessrule)
    Get-ChildItem -Path "$mypath" -Recurse -Force | Set-Acl -AclObject $myacl -Verbose
    

    Verbosity is optional in the last line

提交回复
热议问题