Powershell Script to transpose rows into columns


A question was posted on Windows Powershell peer support forum that asked if array data can be transposed where a table rows can be transposed into columns:

trans5

I found this to be an interesting question and put this script to answer it. The script can be downloaded from the Microsoft Script Center Repository. This script has been updated and republished in the Microsoft PowerShell Gallery on 11 October 2021.

This script will take array input similar to the following which would be the content of .\table1.csv sample input file used in the script:

Server,Property,Value
Srv1,Memory,4GB
Srv1,Processes,135
Srv1,Storage,120GB
Srv2,Memory,8GB
Srv2,Processes,234
Srv2,Storage,120GB
Srv3,Memory,16GB
Srv3,Processes,239
Srv3,Storage,160GB
Srv4,Memory,10GB
Srv4,Processes,219
Srv4,Storage,100GB

trans3

The script will transpose it by “Property”, grouped by “Server”, where intersection of Property X Server = Value. The result will look like:

trans4

trans6

2 responses

  1. Gary Wan

    cannot download the script from the site anymore

    October 11, 2021 at 1:39 am

    • Updated and republished in the PowerShell Gallery, see above.

      October 11, 2021 at 11:38 am

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.