Format

The -f operator can be used to create complex formatted strings. The syntax for the format operator is inherited from .NET; MSDN has a number of advanced examples: https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx#Starting.

The -f operator uses a number in curly braces ({<number>}) in a string on the left of the operator to reference a value in an array on the right, for example:

'1: {0}, 2: {1}, 3: {2}' -f 1, 2, 3 

The format operator is one possible way to assemble complex strings in PowerShell. In addition to this, it may be used to simplify some string operations. For example, a decimal may be converted into a percentage:

'The pass mark is {0:P}' -f 0.8 

An integer may be converted into a hexadecimal string:

'244 in Hexadecimal is {0:X2}' -f 244 

A number may be written as a culture-specific currency:

'The price is {0:C2}' -f 199 
Reserved characters

When using the -f operator, curly braces are considered reserved characters. If a curly brace is to be included in a string as a literal value, it can be escaped: 'The value in {{0}} is {0}' -f 1.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.74.227