PowerShell To Set Folder Permissions

前端 未结 5 828
旧时难觅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:29

    Referring to Gamaliel 's answer: $args is an array of the arguments that are passed into a script at runtime - as such cannot be used the way Gamaliel is using it. This is actually working:

    $myPath = 'C:\whatever.file'
    # get actual Acl entry
    $myAcl = Get-Acl "$myPath"
    $myAclEntry = "Domain\User","FullControl","Allow"
    $myAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($myAclEntry)
    # prepare new Acl
    $myAcl.SetAccessRule($myAccessRule)
    $myAcl | Set-Acl "$MyPath"
    # check if added entry present
    Get-Acl "$myPath" | fl
    

提交回复
热议问题