Melody975 Melody975 - 1 year ago 127
PowerShell Question

How can I change the headings of hash table columns in powershell script

I am fairly new to Powershell scripting. I am writing a power-shell script in which I declared a hash table like the following:

$a = 1
$b = 2

$my_hash = @{}
$my_hash.Add($a, $b)

When I print the table in Powershell, the headings of the hash table shows

Name Value
---- -----
1 2

How can I change the name of each column from "Name, Value" to something like "Application1, Application2"?

App1 App2
---- -----
1 2

Appreciate the help!

Answer Source

Pipe the hashtable to a Select command, and build your output on the fly such as:

$My_Hash.keys | Select @{l='App1';e={$_}},@{l='App2';e={$My_Hash.$_}}