默認目錄的權限是繼承父目錄的,你當然可以關閉它的繼承和分配指定的權限。
下面例子創建了“PermissionNoInheritance”的文件夾,允許當前用戶讀取,同時管理員組獲得其所有管理權限,并關閉它的繼承。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# create folder $Path = 'c:\PermissionNoInheritance' $null = New-Item -Path $Path -ItemType Directory -ErrorAction SilentlyContinue # get current permissions $acl = Get-Acl -Path $path # add a new permission for current user $permission = $ env :username, 'Read,Modify' , 'ContainerInherit, ObjectInherit' , 'None' , 'Allow' $rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission $acl.SetAccessRule($rule) # add a new permission for Administrators $permission = 'Administrators' , 'FullControl' , 'ContainerInherit, ObjectInherit' , 'None' , 'Allow' $rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission $acl.SetAccessRule($rule) # disable inheritance $acl.SetAccessRuleProtection($ true , $ false ) # set new permissions $acl | Set-Acl -Path $path |