【发布时间】:2019-12-26 21:51:21
【问题描述】:
我希望将一组 hastables 显示为表格。我找到了几个处理这个问题的线程,但到目前为止还没有解决方案对我有用(参见 here 和 here)。
我的数组包含 18 个这种形式的哈希表:
Array = @(
@{Company=1}
@{Company=2}
@{Company=3}
@{Contact=X}
@{Contact=Y}
@{Contact=Y}
@{Country=A}
@{Country=B}
@{Country=C}
)
我想得到以下输出:
Company Contact Country
------------------------------
1 X A
2 Y B
3 Z C
我尝试了以下方法:
$Array | ForEach-Object { New-Object -Type PSObject -Property $_ } | Format-Table
显示如下:
Company
----------
1
2
3
Format-List 效果更好;然后我得到这个:
Company: 1 2 3
Contact: X Y Z
Country: A B C
有什么方法可以完成我想要的输出吗?
【问题讨论】:
标签: arrays powershell format hashtable