PowerShell脚本帮助-从现有CSV文件获取ACL,然后附加到新的CSV文件

PowerShell脚本帮助-从现有CSV文件获取ACL,然后附加到新的CSV文件,powershell,Powershell,我有一个名为“C:\testing\blah.CSV”的CSV文件,格式如下: "Agent Name","Agent Type","File Name","Location","Added (GMT)","Created (GMT)","Last Modified (GMT)","File Size (Bytes)","Fil

我有一个名为“C:\testing\blah.CSV”的CSV文件,格式如下:

"Agent Name","Agent Type","File Name","Location","Added (GMT)","Created (GMT)","Last Modified (GMT)","File Size (Bytes)","File Size","Extension","Incident Type","Flagged","Ignored","Location + File Name"
"Server","file","blah5.txt","\\127.0.0.1\c$\temp","10/8/2020 21:13","10/8/2020 19:33","10/8/2020 16:26","10723331","10.23 (MB)","txt","ssn_medium_data_discover","FALSE","FALSE","\\127.0.0.1\c$\temp\blah5.txt"
我想在blah.csv文件的“Location+File Name”列上运行Powershell命令“get acl”,并将其输出到一个新的csv,其中Owner和AccessToString作为新列。到目前为止,我运气不太好-以下是我的代码:

$file2 = import-csv -path "C:\testing\blah.csv"

ForEach ($file in $file2) {
   get-acl -path $file."Location + File Name" | Select-Object Owner,AccessToString 
    }

你能指引我正确的方向吗?最终结果应该是原始csv中的所有列以及两个新列(Owner、AccessToString),这些新列使用get-acl中的值填充。

使用
Import-csv
cmdlet,您可以获得一个PSCUTOObject数组,因此很容易在这些列上添加一些属性,然后重新导出到新的csv:

$file2 = Import-Csv -Path "C:\testing\blah.csv"

ForEach ($file in $file2) {
   $infoSec = Get-Acl -Path $file."Location + File Name" | Select-Object Owner, AccessToString 
   $file | Add-Member -MemberType NoteProperty -Name "Owner" -Value $infoSec.Owner
   $file | Add-Member -MemberType NoteProperty -Name "AccessToString" -Value $infoSec.AccessToString
   $file | Export-Csv -Path C:\testing\newBlah.csv -Encoding UTF8 -NoTypeInformation -Append
}
但是,如果可以的话,应该避免将属性名与空格一起使用,如下所示:

"AgentName","AgentType","FileName","Location","AddedGMT","CreatedGMT","ModifiedGMT","FileSizeBytes","FileSize","Extension","IncidentType","Flagged","Ignored","FullName"
因此,您可以将
Get Acl
行替换为:

$infoSec = Get-Acl -Path $file.FullName | Select-Object Owner, AccessToString