Powershell获取文件夹权限而不继承

问题描述 投票:1回答:1

我想知道是否有一种简单的方法来列出文件夹及其所有子文件夹的权限,但是一旦权限从上面的文件夹继承,它就不应该列出文件夹,因为那时我的列表会太大。我有一些工作方式的代码来检查文件夹权限,但现在,它还列出了具有继承权限的文件夹。

$User = "Testumgebung\cbruehwiler"
$UserOhneDomain = "cbruehwiler"
$Path = "T:\"
$List = New-Object System.Collections.Generic.List[System.Object]
$Groups = Get-ADPrincipalGroupMembership $UserOhneDomain

$GroupArrayList = New-Object System.Collections.ArrayList
foreach ($Group in $Groups) {
    $GroupArrayList.Add($Group.Name) | Out-Null
}

# Fields we want in list, an array of calculated properties.
$OutputFields = @(
    @{name="Item" ;       expression={$_.Path.split(':',3)[-1]}}
    @{name="Rights" ;     expression={$Right.FileSystemRights}}
    @{name="AccessType" ; expression={$Right.AccessControlType}}
    @{name="From" ;       expression={$User}}
)
$FileSystemObjects = Get-ChildItem $Path -Recurse | ForEach-Object {Get-Acl $_.FullName}

foreach ($Item in $FileSystemObjects) {
    foreach ($Right in $Item.Access) {
        if ($Right.IdentityReference -eq $User) {
            $List.Add(($Item | Select-Object $OutputFields))
        }
    }
}

foreach ($Item in $FileSystemObjects) {
    foreach ($Right in $Item.Access) {
        foreach ($GroupArrayItem in $GroupArrayList){
            if ($Right.IdentityReference -eq ("TESTUMGEBUNG\" + $GroupArrayItem)) {
                $List.Add(($Item | Select-Object $OutputFields))
            }
        }
    }
}

$List | Out-File C:\Users\cbruehwiler\Desktop\PermissionCheck.txt
powershell inheritance active-directory powershell-v2.0 acl
1个回答
1
投票

您可以使用每次访问的IsInherited值对其进行过滤。

if($Right.IsInherited -eq $false){
    //do stuff
}
© www.soinside.com 2019 - 2024. All rights reserved.