获取文件或文件夹访问权限:
Get-Acl -Path <File or Folder Path> | Format-List
修改文件访问权限:
修改文件访问权限需要用到Set-Acl命令,使用-Path参数指定要修改的文件路径,使用-AclObject参数指定一个对象,该对象相当于一个ACL模板,此ACL模板指定了用户访问资源的权限设定。该对象的设定需要调用"System.Security.AccessControl.FileSystemAccessRule"类。
1: $account = "test01win2k8r2\test"
2: $FileSystemRights = "FullControl"
3: $objType = [System.Security.AccessControl.AccessControlType]::Allow
4:
5: $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ($account,$FileSystemRights,$objType)
6: $Folder = "W:\Test\test.txt"
7: $acl = Get-Acl $Folder
8: $acl.SetAccessRule($accessRule)