Different result format when use get-wmiobject

Hi all,

I’m a newbie in PowerShell. Please help explain to me why we have different format result in this case

1st case:

get-wmiobject win32_logicaldisk | select Name,FileSystem,VolumeName,@{'Name'='Remain' ;e={[math]::truncate($_.freespace / 1GB)}}

1st result:

Name FileSystem VolumeName Remain
---- ---------- ---------- ------
C:   NTFS       OSDisk     80

 

2nd case:

 get-wmiobject win32_logicaldisk | select Name,FileSystem,VolumeName,@{'Name'='Size' ;e={[math]::truncate($_.size / 1GB)}},@{'Name'='Remain' ;e={[math]::truncate($_.freespace / 1GB)}}

2nd result

Name : C:
FileSystem : NTFS
VolumeName : OSDisk
Size : 235
Remain : 80

Besides, can we use less command for getting the same result?

 

 

That’s the automatic formatting system of Powershell. If you have up to 4 properties you get a table view by default. If it’s more you get a list view by default. If you want to have something particular you should use either Format-Table or Format-List or one of the other format cmdlets.

You could use aliasses but in the end that would be same cmdlets. Sometimes you need a certain amount of code to get a particular output. :wink:

You must use “| format-table” if you want the same “view” as in the first one.

Edit: Just saw previous reply

thanks a lot. I made it