当前位置: 代码网 > it编程>前端脚本>Powershell > Powershell目录文件夹管理权限的继承和指定方法

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

2024年05月18日 Powershell 我要评论
默认目录的权限是继承父目录的,你当然可以关闭它的继承和分配指定的权限。下面例子创建了“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

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com