使用路径将Get-ACL导出为CSV

时间:2014-09-27 11:17:14

标签: powershell export-to-csv

我正在使用PowerShell 4并创建了一个脚本,该脚本获取文本文件中列出的共享并将ACL信息输出到CSV文件。问题是我无法弄清楚如何导出包括文件夹路径。这是我的剧本:

$InputFile = "C:\Folders.txt"
$OutputFile = "C:\FolderPermissions.csv"
$FolderList = Get-Content $InputFile

ForEach ($Folder in $FolderList)
{
    $Permissions = (Get-ACL $Folder).access
    $Report += $Permissions
}

$Report | Select-Object IdentityReference,FileSystemRights,IsInherited | Export-CSV $OutputFile -NoTypeInformation

我已经使用下面的行成功添加并导出了单个文件夹,但是只要我组合对象,就会导出唯一的列名,没有值。

$Folder = "\\server\share"
$Name=Folder
$Permissions = (Get-ACL $Folder).access
$Permissions | Add-Member -MemberType NoteProperty -Name $Name -Value $Folder

$Permissions | Select-Object Folder,IdentityReference,FileSystemRights,IsInherited | Export-CSV $OutputFile -NoTypeInformation

解决方案:

再次感谢你们! MFT的答案通过一些调整解决了它。这是我想要的过滤器的工作代码。请注意.IsInherited过滤器使用-eq“TRUE”返回不正确的数据,但使用-ne“FALSE”成功运行。

$InputFile = "C:\Folders.txt"
$OutputFile = "C:\FolderPermissions.csv"
$FolderList = Get-Content $InputFile

ForEach ($Folder in $FolderList)
{
    $Permissions = (Get-ACL $Folder).access | ForEach-Object {$_ |
        Add-Member -MemberType NoteProperty -Name Folder -Value $Folder}
    $Report += $Permissions
}

$Report | Select-Object Folder,IdentityReference,FileSystemRights,IsInherited |
    Where {$_.Folder -ne $Null -and $_.IdentityReference -like "HARRAHS*" -and $_.IsInherited -ne "TRUE"} |
    Export-CSV $OutputFile -NoTypeInformation

2 个答案:

答案 0 :(得分:0)

你走在正确的轨道上。为每个访问列表项添加路径属性将实现您的目标。

# Get access list items of the folder
$Permissions = (Get-Acl -Path $Folder).Access | 

    # Add the path property and assign its value, -PassThru so the object is assigned to $Permissions
    ForEach-Object { $_ | Add-Member -MemberType NoteProperty -Name Path -Value $Folder -PassThru }

答案 1 :(得分:0)

这将为您提供格式良好的CSV

gps.Raise(x => x.GpsLocationUpdated += (sender, e) => { }, this, new GpsLocation(0, 0));