Sometimes in Powershell the Column label names can be not very intuitive or you may have to present the results to a non technical person who may not understand. In this case we can edit the labels to suit our needs.
The format is quite simple we will use Get-Process in this example. When filtering the property you wish to change the label of use the following code:
@{} Use @ and all your code for the custom column goes between the curly brackets.
Inside of the curly brackets insert the following:
Label="Custom column Label";
Expression={$_.Property Name}
And all together it will look like below.
Get-Process | Format-Table Name,ID,@{Label="Paged Memory Size";Expression={$_.PM }} -AutoSize
You can also further format the output so it better suits your needs. Here we will use Get-WmiObject to see available disk space and format the column header and the output to show us how many GB of free space we have to 2 decimal places.
Here we nee to add some extra code to get the outcome we desire.
/1GB We have divided the $_.freespace property by 1GB you can also divide it by MB,TB and PB if you desire.
formatstring="N2" restricts the output to 2 decimal places you just need to change the number after the N if you desire more or less decimal places.
width=20 Specifies the column header width.
align="Left" Sets the alignment of the data within the column.
All together it looks like:
@{Name="FreeSpaceGB";Expression{$_.freespace /1GB};formatstring="N2";width=20;align="left"}
And the full script will look like:
Get-WmiObject Win32_LogicalDisk -Filter DriveType=3 | Format-Table SystemName,VolumeName,DeviceId,@{Name="Free Space GB";Expression={$_.freespace / 1GB};formatstring="N2";width=20;align="left"}