PowerTip: Creating a Custom Number Display


Summary: Learn how to create a custom number display.

Question: How do I display a “calculated value” (megabytes instead of bytes) from a WMI query when piping data into a Format-Table cmdlet?

Answer: Create a hash table where you want to display the data, and perform the calculation inside curly brackets, and then assign the results to the expression parameter as shown here:

gwmi win32_logicaldisk -Filter “drivetype=3″ | ft -Property name, @{ Label=”freespace”; expression={$_.freespace/1MB}}

Comments (2)

  1. mredwilson says:

    @Mike Shepard that is not being picky … it causes the code to fail … not sure where that – came from …

    Thanks for pointing it out. I have now fixed it.

  2. Mike Shepard says:

    Being picky here, but there's an extra hyphen in the Label key in the hashtable (La-bel).

Skip to main content