【问题标题】:Powershell get Folder permissions without inheritancePowershell无需继承即可获得文件夹权限
【发布时间】:2019-09-19 02:02:30
【问题描述】:

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

$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-2.0 acl


    【解决方案1】:

    您可以使用每次访问的IsInherited 值将其过滤掉。

    if($Right.IsInherited -eq $false){
        //do stuff
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-15
      • 2013-07-30
      • 2015-12-05
      • 1970-01-01
      • 2021-11-01
      • 2021-12-28
      • 2017-02-24
      • 1970-01-01
      • 2010-12-04
      相关资源
      最近更新 更多