Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hashtable output column titles

Tags:

powershell

Consider these 2 hashtables

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

As you can see, they each get a column title when shown on screen.

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

However, when I output them both in 1 command, the column titles are shown only once.

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

Even when I add a separator line, the column titles are still only shown once.

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

Why is that?
And is there a way to get the column titles to show again on the output of myHash2 ?
Something like this

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
like image 570
Bjorn Mistiaen Avatar asked Jun 29 '26 13:06

Bjorn Mistiaen


1 Answers

this should help you :

$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
like image 96
ClumsyPuffin Avatar answered Jul 01 '26 06:07

ClumsyPuffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!