【发布时间】:2020-06-17 21:33:22
【问题描述】:
我的 powershell 代码:
$h1 = [ordered]@{
"item1" = "command1"
"item2" = "command2"
"item3" = "command3"
"item4" = "command4"
"item5" = "command5"
}
$h2 = [ordered]@{
"col1" = "result1"
"col2" = "result2"
}
$h1.GetEnumerator() | Format-Table @{
Label = "Item";
Expression = { $_.Key }
}, @{
Label = "Command";
Expression = { $_.Value }
}
$h2.GetEnumerator() | Format-Table @{
Label = "Column";
Expression = { $_.Key }
}, @{
Label = "Result";
Expression = { $_.Value }
}
输出
Item Command
---- -------
item1 command1
item2 command2
item3 command3
item4 command4
item5 command5
Column Result
------ ------
col1 resul1
col2 resul2
期望的输出
Item Command Column Result
---- ------- ------ ------
item1 command1 col1 resul1
item2 command2 col2 resul2
item3 command3
item4 command4
item5 command5
我正在尝试显示两个并排的哈希表。是否可以使用 2 个哈希表?或者我应该使用两个数组?
基本上我只想显示多列,但数据不均匀,如我想要的输出所示。
任何帮助将不胜感激。
【问题讨论】:
标签: arrays powershell formatting hashtable tabular