从多个服务器获取单个文件夹的访问控制列表

时间:2014-10-04 10:42:23

标签: powershell

目前,我正在执行脚本,以便从多个服务器获取单个文件夹的访问控制列表。在执行脚本时,我已将访问列表收到System.Security.AccessControl.AuthorizationRuleCollection

$a = @()
$servers = Get-Content "F:\Team CDS\ExchServerlist.txt"
ForEach ($server in $servers)
{
$b = New-Object System.Object
$b = get-acl "\\$server\F$\Team CDS" | select-object -property @{Name = 'Path'; Expression = { ($_.PSPath -split '::')[1]; } },owner,access
$a += $b
$a | Export-Csv -NoTypeInformation -Path "F:\access1.csv"
}

输出:

\\9021\F$\Team CDS","OnlyL3","System.Security.AccessControl.AuthorizationRuleCollection"
\\9022\F$\Team CDS","OnlyL3","System.Security.AccessControl.AuthorizationRuleCollection"
\\9022\F$\Team CDS","OnlyL3","System.Security.AccessControl.AuthorizationRuleCollection"

请帮我在输出文件中更新访问属性。

1 个答案:

答案 0 :(得分:0)

我通常会扩展ACL,只需将安全描述符中需要的路径和其他信息添加到每个对象中:

Get-Content "F:\Team CDS\ExchServerlist.txt" | ForEach-Object {

    $Path = "\\$_\F$\Team CDS"

    $Acl = Get-Acl $Path
    $Acl | 
        Select-Object -ExpandProperty Access | 
        Add-Member -MemberType NoteProperty -Name Path -Value $Path -PassThru  |
        Add-Member -MemberType NoteProperty -Name Owner -Value $Acl.Owner -PassThru

} | Export-Csv -NoTypeInformation -Path "F:\access1.csv"