August 8th, 2012

PowerTip: Creating a Custom Number Display

Doctor Scripto
Scripter

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

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.