Powershell Format Operator (-f)

Padding Prefix
PS C:\Users\User> 1..10 | % { “{0:d2}” -f $_}
01
02
03
04
05
06
07
08
09
10
Space Padding

PS C:\Users\User> 1..10 | % { "{0,5}" -f $_}
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10

Number of decimal places
PS C:\Users\User> 1..10 | % { “{0:n2}” -f $_}
1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
10.00
Percentage
PS C:\Users\User> 1..10 | % { “{0:p2}” -f ($_/4)}
25.00 %
50.00 %
75.00 %
100.00 %
125.00 %
150.00 %
175.00 %
200.00 %
225.00 %
250.00 %
Ref – https://blogs.technet.microsoft.com/pstips/2014/10/18/powershells-format-operator/

Leave a comment

Your email address will not be published. Required fields are marked *

WordPress Appliance - Powered by TurnKey Linux