Summary: Learn how to format numeric output in Windows PowerShell by using format specifiers and numeric constants.
How can I print the amount of free space on a fixed disk in MB with two decimal places?
Use a format specifier as shown here:
“{0:n2}”-f ((gwmi win32_logicaldisk -Filter “drivetype=’3′”).freespace/1MB)
What if I want to display the output in GB with three decimal places?
Use a format specifier as shown here:
“{0:n3}”-f ((gwmi win32_logicaldisk -Filter “drivetype=’3′”).freespace/1GB)
I like big numbers. Can I display it in KB and have five decimal places?
Use a format specifier as shown here:
“{0:n5}”-f ((gwmi win32_logicaldisk -Filter “drivetype=’3′”).freespace/1KB)
I want something simple. Can I print the amount of free space on a fixed disk in MB in whole numbers?
No need for a format specifier, as shown here:
[int] ((gwmi win32_logicaldisk -Filter “drivetype=’3′”).freespace/1MB)
0 comments