Windows PowerShell offers several facilities for working with plain-text data.
To define a literal string (one in which no variable or escape expansion occurs), enclose it in single quotes:
$myString = 'hello `t $ENV:SystemRoot' $myString gets the actual value of hello `t $ENV:SystemRoot
To define an expanding string (one in which variable and escape expansion occurs), enclose it in double quotes:
$myString = "hello `t $ENV:SystemRoot" $myString gets a value similar to hello C:\WINDOWS
To include a single quote in a single-quoted string, or a double quote in a double-quoted string, you may include two of the quote characters in a row:
PS >"Hello ""There""!" Hello "There"! PS >'Hello ''There''!' Hello 'There'!
To include a complex expression inside of an expanding string, use a subexpression. For example:
$prompt = "$(get-location) >" $prompt gets a value similar to c:\temp >
Accessing the properties of an object counts as a complex expression:
$output = "Current script name is: $($myInvocation.MyCommand.Path)"
$output gets a value
Current script name is
To define a here string (one that may span multiple lines), place the two characters @” at the beginning, and the two characters “@ on their own line at the end.
$myHereString = @" This text may span multiple lines, and may contain "quotes". "@
Here strings may be of either the literal or expanding variety.
Windows PowerShell supports the ...