Tuesday, February 26, 2013

String formatting in PowerShell

If you want to perform a string.Format in PowerShell (much like you would do in C#), you can do so using the following syntax:

[string]::Format("This is my variable: {0}", $myVariable)

Alternatively, you can also perform string formatting this way:

"This is my variable: {0}" -f $myVariable

If you have multiple variables, you can simply comma separate the values in the formatted string:

"This is some text: {0} and this is some value {1}" -f $text, $value





No comments:

Post a Comment