Well, I hope I am finding you well after the new year.
I do not need you to tell what great things you can do with powershell, but I really wanted to share this great thing with you.
It is called formatting with .net.
String Formatting Syntax
The format string supported by the format (-f) operator is a string that contains format items. Each format item takes the form of:
{index[,alignment][:formatstring]}
Custom Numeric Format Strings
You may use custom numeric format strings to format numbers in ways not supported by the standard format strings.
Format specifier (Name) | Description | Example | ||
---|---|---|---|---|
0 (Zero placeholder) | Specifies the precision and width of a number string. Zeroes not matched by digits in the original number are output as zeroes. |
|
||
# (Digit placeholder) | Specifies the precision and width of a number string. # symbols not matched by digits in the input number are not output. |
|
||
. (Decimal point) | Determines the location of the decimal separator. |
|
||
, (Thousands separator) | When placed between a zero or digit placeholder before the decimal point in a formatting string, adds the separator character between number groups. |
|
||
, (Number scaling) | When placed before the literal (or implicit) decimal point in a formatting string, divides the input by 1,000. You may apply this format specifier more than once. |
|
||
% (Percentage placeholder) | Multiplies the input by 100 and inserts the percent sign where shown in the format specifier. |
|
||
E0E+0E-0e0e+0e-0
(Scientific notation) |
Displays the input in scientific notation. The number of zeroes that follow the E define the minimum length of the exponent field. |
|
||
'text' "text" (Literal string) | Inserts the provided text literally into the output without affecting formatting. |
|
||
; (Section separator) | Allows for conditional formatting. If your format specifier contains no section separators, then the formatting statement applies to all input. If your format specifier contains one separator (creating two sections), then the first section applies to positive numbers and zero. The second section applies to negative numbers. If your format specifier contains two separators (creating three sections), then the sections apply to positive numbers, negative numbers, and zero. |
|
||
Other (Other character) | Inserts the provided text literally into the output without affecting formatting. |
|
Standard Numeric Format Strings
All format specifiers may be followed by a number between 0 and 99 to control the precision of the formatting.
wvsandwijk
I am a Technical Specialist - Cloud Infrastructures from the Netherlands.
My Skills are mainly PowerShell, VMWare, Hyper-V, Microsoft System Center products and Windows Azure Pack.
I work for a company in Utrecht The Netherlands.
My Skills are mainly PowerShell, VMWare, Hyper-V, Microsoft System Center products and Windows Azure Pack.
I work for a company in Utrecht The Netherlands.
Latest posts by wvsandwijk (see all)
- [PS] VMware ESX Certificate validation - September 7, 2018
- PoSH-Git : unable to start ssh-agent service, error :1058 - July 22, 2018
- [PS] Speedup VMWare PowerShell module - June 11, 2018