【发布时间】:2017-03-29 09:40:26
【问题描述】:
所以我有这个脚本,它从 xml 中获取数据,特别是机器的名称,然后是每个机器的 ID 号列表。我可以将每个变量都放入变量中,但是当我尝试列出所有 id 时,只有每个 id 的第一个元素出现。我认为 Export-CSV -Append 可以解决这个问题,但到目前为止什么都没有。
$path="C:\Users\Desktop\DataIDs"
$xmls = Get-ChildItem $path\* -Recurse | where {$_.Name -like '*DataIDX*'}
$results = New-Object psobject
ForEach ($xml in $xmls) {
[xml]$results = Get-Content $xml
$Name = $results.Benchmark.TestResult.target
$VID1 = @($results.Benchmark.TestResult.'rule-result' | where {$_.result -eq 'fail'}).Version | Sort-Object
$VID = $VID1 | Out-String
ForEach ($id in $VID) {
$results | Add-Member -MemberType NoteProperty -Name $Name -Value $id
}
}
$results | Export-Csv $path\results.csv -NoTypeInformation -Append
Remove-Variable results
【问题讨论】:
标签: xml powershell foreach formatting export-to-csv