首页 > 解决方案 > 使用powershell向目录NTFS权限添加条件

问题描述

我想使用 PowerShell 将条件添加到文件夹的 NTFS 权限。PowerShell可以做到这一点吗?

我用谷歌搜索,但找不到任何东西。我创建一个脚本来添加或删除文件夹 ACL 中的规则没有问题。

这是我创建的一个函数,但想向 ACL 添加一个条件:

    function AssignArchivePermissions($path){

    $NTGroup="SG-ServerOperators"
    $FileSystemRights="Modify"
    $InheritanceFlags="ContainerInherit,ObjectInherit"
    $PropagationFlags="None"
    $AccessControlType="Allow"

    $DenyGroup="CDIR-DenyDelete"
    $acl = (get-item $path ).GetAccessControl('Access')

    $aclst = $acl.Access

    foreach($identity in  $aclst.IdentityReference){
         if($identity.Value -eq "domainname\$DenyGroup"){
            $oldrule = New-Object System.Security.AccessControl.FileSystemAccessRule("domainname\$DenyGroup", $aclst.FileSystemRights,$aclst.InheritanceFlags,$aclst.PropagationFlags,$aclst.AccessControlType)
             write-host "`n`r`n`r Removing $DenyGroup from $path ACL...`n`r"
            $acl.RemoveAccessRule($oldrule)
        }
    }

    try{
        $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("domainname\$NTGroup",$FileSystemRights,$InheritanceFlags,$PropagationFlags,$AccessControlType)

        write-host "`n`r`n`r Adding $NTGroup to $path ACL...`n`r"

        $acl.AddAccessRule($rule)

        Set-Acl -Path $path -AclObject $acl

    }
    catch{}
}

标签: .netpowershellactive-directoryntfs

解决方案


推荐阅读