Skip navigation

Q. What is a here-string in Windows PowerShell?

A. Normally, a Windows PowerShell string is delimited by either single or double quotation marks:

$a = "String"
$b = 'String'

When you need to include a large block of strings that include single and double quotation marks, it can get complicated because you’re required to escape any quotation marks that are also being used to delimit the string:

$a = "This is my 'string,' and it contains `"quotes`"."

A here-string helps to avoid this by defining a block of text. You begin a here-string by using @" and end it by using "@.

There are some specific rules for where those starting and ending marks appear. You have to type it just as follows: The @" must be the last thing on the first line, then you type whatever arguments you want passed, and finally the closing "@ must be the first two characters on the next line:

$a = @"
This is a here-string. I can type "anything" I want,
even carriage returns, and it will all be preserved.
No need to escape!
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.