PowerShell Creating a basic string



Strings are created by wrapping the text with double quotes. Double-quoted strings can evalute variables and special characters.

$myString = "Some basic text"
$mySecondString = "String with a $variable"

To use a double quote inside a string it needs to be escaped using the escape character, backtick (`). Single quotes can be used inside a double-quoted string.

$myString = "A `"double quoted`" string which also has 'single quotes'."

Literal string

Literal strings are strings that doesn't evaluate variables and special characters. It's created using single quotes.

$myLiteralString = 'Simple text including special characters (`n) and a $variable-reference'

To use single quotes inside a literal string, use double single quotes or a literal here-string. Double qutoes can be used safely inside a literal string

$myLiteralString = 'Simple string with ''single quotes'' and "double quotes".'