February 2019
Intermediate to advanced
626 pages
15h 51m
English
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 ...
Read now
Unlock full access