考虑这两个哈希表

$myHash1 = @{one=1;two=2;three=3;four=4;five=5}
$myHash2 = @{six=6;seven=7;eight=8;nine=9;ten=10}

如您所见,当它们显示在屏幕上时,它们每个都有一个列标题。
PS C:\> $myHash1

Name         Value
----         -----
four         4
five         5
one          1
three        3
two          2


PS C:\> $myHash2

Name         Value
----         -----
six          6
nine         9
seven        7
ten          10
eight        8

但是,当我在1命令中将它们都输出时,列标题仅显示一次。
PS C:\> $myHash1;$myHash2

Name         Value
----         -----
four         4
five         5
one          1
three        3
two          2
six          6
nine         9
seven        7
ten          10
eight        8

即使添加分隔线,列标题仍仅显示一次。
PS C:\> $myHash1;Write-Output 'separator line';$myHash2

Name         Value
----         -----
four         4
five         5
one          1
three        3
two          2
separator line
six          6
nine         9
seven        7
ten          10
eight        8

这是为什么?
有没有办法使列标题再次显示在myHash2的输出上?
像这样
Name         Value
----         -----
four         4
five         5
one          1
three        3
two          2
separator line
Name         Value
----         -----
six          6
nine         9
seven        7
ten          10
eight        8

最佳答案

这应该可以帮助您:

$myHash1 = @{one=1;two=2;three=3;four=4;five=5}
$myHash2 = @{six=6;seven=7;eight=8;nine=9;ten=10}
#you can also use $myHash1 | Out-String also
$myHash1 | ft
Write-Output "separator"
$myHash2 | ft

关于powershell - 哈希表输出列标题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41444440/

10-13 09:18