powershell - 使用 set-acl 和 powershell 设置继承和传播标志

标签 powershell permissions file-permissions

我试图模仿右键单击文件夹、在文件夹上设置“修改”并将权限应用于特定文件夹、子文件夹和文件的操作。

我主要使用 Powershell,但是继承仅设置为“子文件夹和文件”,而不是整个“此文件夹、子文件夹和文件”。

System.Security.AccessControl.PropagationFlags 是否有一些未列出的标志可以正确设置?

这是我迄今为止正在处理的内容。

$Folders = Get-childItem c:\TEMP\
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly
$objType = [System.Security.AccessControl.AccessControlType]::Allow 

foreach ($TempFolder in $Folders)
{
echo "Loop Iteration"
$Folder = $TempFolder.FullName

$acl = Get-Acl $Folder
$permission = "domain\user","Modify", $InheritanceFlag, $PropagationFlag, $objType
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission

$acl.SetAccessRule($accessRule)
Set-Acl $Folder $acl
} 

最佳答案

下表可帮助查找不同权限组合所需的标志。

    ╔═════════════╦═════════════╦═══════════════════════════════╦════════════════════════╦══════════════════╦═══════════════════════╦═════════════╦═════════════╗
    ║             ║ folder only ║ folder, sub-folders and files ║ folder and sub-folders ║ folder and files ║ sub-folders and files ║ sub-folders ║    files    ║
    ╠═════════════╬═════════════╬═══════════════════════════════╬════════════════════════╬══════════════════╬═══════════════════════╬═════════════╬═════════════╣
    ║ Propagation ║ none        ║ none                          ║ none                   ║ none             ║ InheritOnly           ║ InheritOnly ║ InheritOnly ║
    ║ Inheritance ║ none        ║ Container|Object              ║ Container              ║ Object           ║ Container|Object      ║ Container   ║ Object      ║
    ╚═════════════╩═════════════╩═══════════════════════════════╩════════════════════════╩══════════════════╩═══════════════════════╩═════════════╩═════════════╝

所以,as David said ,你会想要

InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit
PropagationFlags.None

关于powershell - 使用 set-acl 和 powershell 设置继承和传播标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3282656/

相关文章:

powershell - 有什么方法可以告诉以 start-job -filename 启动时正在运行的脚本是什么?

ios - 无权查看打开操作时从 iOS 文档提供程序传回的文档

Android - 将操作系统升级到 Marshmallow 后,权限如何在已安装的应用程序上运行

读取时出现 Python 权限错误

deployment - phpStorm 在 sftp 部署期间失去权限

sql - Azure SQL Powershell,如何读取数据 View

powershell - 在PowerShell中为findstr/grep输出着色

powershell - Powershell : cannot hide 'Access is denied' error on 'Remove-Item'

hadoop - 使用配置单元初始化数据库时出现 java.sql.SQLException : Failed to start database 'metastore_db' ERROR,

python - Jupyter 笔记本 : "RuntimeError: Permissions assignment failed for secure file: ... Got ' 0o160 0' instead of ' 0o060 0' "