windowspowershellscriptinghashtablepowershell-2.0

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"? I.e.

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

Appreciate the help!


Solution

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

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