PowerTip: Creating a Custom Number Display

PowerTip: Creating a Custom Number Display

  • Comments 2
  • Likes

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}}

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Being picky here, but there's an extra hyphen in the Label key in the hashtable (La-bel).

  • @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.