default output of get-psdrive

How is the default output of get-psdrive determined? It’s formatted as a table (not autosized), and Used and Free are given in gigabytes. The output object type is “PSDriveInfo”.

Name           Used (GB)     Free (GB) Provider      Root                                    CurrentLocation
----           ---------     --------- --------      ----                                    ---------------
/                 152.92        293.19 FileSystem    /                                                      

But if I pipe it to format-list * (I have to say ‘*’ to get all properties), Used and Free are given in bytes:

Used                   : 164193693696
Free                   : 314806308864
CurrentLocation        : 
Name                   : /
Provider               : Microsoft.PowerShell.Core\FileSystem
Root                   : /
Description            : /
MaximumSize            : 
Credential             : System.Management.Automation.PSCredential
DisplayRoot            : 
VolumeSeparatedByColon : False

This is by design.
What you are seeing in the list view is the same as you would see if you displayed all the properties

Get-PSDrive | Select -Property * | Where Name -eq ‘C’


Used : 254887346176
Free : 255709757440
CurrentLocation :
Name : C
Provider : Microsoft.PowerShell.Core\FileSystem
Root : C:
Description : Root
MaximumSize :
Credential : System.Management.Automation.PSCredential
DisplayRoot :

Get-PSDrive by itself is a summary of the drive info and uses calculated name properties. This is not uncommon for many cmdlets.

As for the PoSH default view of virtually any output 5 and below is always shown as a table. As shown by the all properties call above.
Output greater than 5 is always a list for the complete detail display.

When you see results like what your post indicates, be sure to do two things so that you grasp what it does and the expected delivery results.

1 - Always look at the help files
Get-Help -Name Get-PSDrive -Full

2 - Always pipe to Get-Member
Get-PSDrive | Get-Member
(Get-PSDrive).Name -eq ‘C’ | Get-Member

3 - Always look at all possible properties.
Get-PSDrive | Select -Property * | Where Name -eq ‘C’

If you prefer a specific output you could simply specify what you need/want. :wink:

The default output is actually determined by the format.ps1xml where that object type exists. In this case that file is $pshome\PowerShellCore.format.ps1xml.

Another good example of this is with Get-Process. The default output for that is:

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------

If you run a Get-Member on Get-Process though you will not find a property named PM(K) or WS(K). It’s just PM or WS. The output is determined by the format.ps1xml that handles process objects. These files aren’t well documented so getting a book like ‘Powershell in Depth’ will definitely help.

To get a list of all the format files run:

Get-ChildItem $pshome -Filter '*.format.ps1xml'

That’s the info I was looking for. I found a help file about it: Hmm can’t find $pshome\PowerShellCore.format.ps1xml in powershell for osx.

Here’s the xml from PowerShellCore.format.ps1xml that sets up the (GB) columns (can’t post xml?):

                    Used (GB)
                    Free (GB)
                            if($_.Used -or $_.Free) { "{0:###0.00}" -f ($_.Used / 1GB) }
                            if($_.Used -or $_.Free) { "{0:###0.00}" -f ($_.Free / 1GB) }
                            if($_.DisplayRoot -ne $null) { $_.DisplayRoot } else { $_.Root }