D.chan D.chan - 3 months ago 18
PowerShell Question

PowerShell "select as" function on variable

This is just a simple question regarding alias issue on PowerShell syntax. Yet I can't find any related solution to it ATM.

Select SystemName , DeviceID,


From the above statement, I would like to display


"DeviceID" as "drives"


and


"SystemName" as "server"


Whole PowerShell script for ref:

$diskvalue += Get-WmiObject @Params | Select SystemName , DeviceID, @{Name=”size(MB)”;Expression={“{0:N1}” -f($_.size/1mb)}}, @{Name=”freespace(MB)”;Expression={“{0:N1}” -f($_.freespace/1mb)}}, @{Name=”UsedSpace(MB)”;Expression={“{0:N2}” -f(($_.size - $_.FreeSpace)/1mb)}}
$diskvalue | Export-Csv C:\example.csv -NoTypeInformation

Answer
select @{l='drives';e='DeviceID'}, @{l='server';e='SystemName'}
Comments