Fabian Mendez's helpful answer bypasses the problem by providing a single-command solution.
As for your symptom:
As you can see it leaves the Free space empty.
No, it simply doesn't print the HDDs FreeSpace
column to the console - though that column (properties by that name on the output objects) still exists, if you were to examine the output programmatically.
In short, your first Get-WmiObject ... | Select-Object
command locks in the display columns, which are Name
and HDDs Total Size In GB
.
While the second command's output has a Name
column, it lacks a HDDs Total Size In GB
column, so no values show up for it - and the HDDs FreeSpace
column is ignored altogether.
This behavior, which relates to implicit use of the Format-Table
output-formatting cmdlet, is explained in detail in this answer of mine.
To force separate output formatting for each command, use ... | Out-Host
or ... | Format-*
(formatting cmdlets such as Format-Table
).
Caveat: Do not do this if you need to process the output programmatically, because Out-Host
bypasses PowerShell's success (data) output stream; while using Format-*
cmdlets would still send data to the success stream, this data is no longer the input objects, but rather objects representing formatting instructions.
Simplified example:
PS> [pscustomobject] @{ one=1; two=2 }; [pscustomobject] @{ one=10; three=30 }
one two
--- ---
1 2
10
Note how column two
is blank for the 2nd object and its three
column doesn't print at all, because only the 1st output object's properties determined the output columns.
Through explicit use of Out-Host
or a formatting cmdlet you can force the two commands to be formatted individually:
PS> [pscustomobject] @{ one=1; two=2 } | Out-Host; [pscustomobject] @{ one=10; three=30 }
one two
--- ---
1 2
one three
--- -----
10 30
Note how each object's columns now show up, preceded by an object-specific header.