将多个ForEach的输出存储到数组中并附加结果powershell

时间:2017-09-27 20:18:32

标签: powershell export-to-csv

$results = @()
foreach($JobObject1 in $JobObjects1){
$Jobs1 = $JobObject1.getAbatObject();
foreach($Job1 in $Jobs1){
write-host("Name :" + $Job1.Name)
write-host("Path :" + $Job1.Path)
}
foreach($JobObject2 in $JobObjects2){
$Jobs2 = $JobObject2.getAbatObject();
foreach($Job2 in $Jobs2){
write-host("Name :" + $Job2.Name)
write-host("Path :" + $Job2.Path)
}
    $details = @{
            TradeSupport_Schedule_Name = $Job1.Name
            TradeSupport_Schedule_Path = $Job1.FullPath
            Operations_Schedule_Name = $Job2.Name
            Operations_Schedule_Path = $Job2.FullPath

    }
    $results += New-Object PSObject -Property $details

write-host("************************************************************")
}
}
$results | select-object -property TradeSupport_Schedule_Name,TradeSupport_Schedule_Path,Operations_Schedule_Name,Operations_Schedule_Path | export-csv -Path \\ch0-craab-01\c$\Support\AB_Reports\Objects_Report.csv -NoTypeInformation 

我正在试图弄清楚如何获取每个foreach语句的输出并将结果存储到数组中,以便我可以将它们组合在csv中。当脚本站立时,它会针对第二个语句迭代第一个语句。我希望每个结果并排打印。

0 个答案:

没有答案