我有一个包含以下字段的CSV文件:
如何使用以下字段创建报告?
$lookupDatafiltered = Import-Csv -Path .\lookups_shutdown.csv
$lookupDatafiltered | Group-Object Region, Country, Status | Select-Object @{n='Region';e={$_.Group[0].Region}}, @{n='Country';e={$_.Group[0].Country}},@{n='Status';e={$_.Group[0].Status}}, Count | Sort-Object -Property Region , Country | export-csv -Path "C:\change\Country.csv" -NoTypeInformation
如何同时获得每个国家/地区导出的CSV的状态计数
使用给定的代码段作为辅助结果:
$lookupDatafiltered = Import-Csv -Path .\lookups_shutdown.csv
$lookupDataAux = $lookupDatafiltered | | Group-Object Region, Country, Status |
Select-Object @{n='Region' ;e={$_.Group[0].Region }},
@{n='Country';e={$_.Group[0].Country}},
@{n='Status' ;e={$_.Group[0].Status }},
Count |
Sort-Object -Property Region, Country, Status
$lookupDataAux | Group-Object -Property Region,Country |
Select-Object @{n='Region' ;e={$_.Group[0].Region }},
@{n='Country';e={$_.Group[0].Country}},
@{n='up' ;e={[int]($_.Group | ForEach-Object { if( $PSItem.Status -EQ 'up' ) { $PSItem| Select-Object -ExpandProperty Count }})}},
@{n='down' ;e={[int]($_.Group | ForEach-Object { if( $PSItem.Status -EQ 'down' ) { $PSItem| Select-Object -ExpandProperty Count }})}},
@{n='total' ;e={($_.Group | Measure-Object -Property Count -Sum).Sum}} |
export-csv -Path "C:\change\Country.csv" -NoTypeInformation
[请考虑将Sort-Object
cmdlet移至后面的管道...