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 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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s