欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Powershell目录文件夹管理权限的继承和指定方法

程序员文章站 2022-03-12 22:07:10
默认目录的权限是继承父目录的,你当然可以关闭它的继承和分配指定的权限。 下面例子创建了“permissionnoinheritance”的文件夹,允许当前用户读取,同时管...

默认目录的权限是继承父目录的,你当然可以关闭它的继承和分配指定的权限。
下面例子创建了“permissionnoinheritance”的文件夹,允许当前用户读取,同时管理员组获得其所有管理权限,并关闭它的继承。

# 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