According to Powershell "about quoting rules":
A here-string is a single-quoted or double-quoted string in which quotation marks are interpreted literally.
However the following here-string results in a TerminatorExpectedAtEndOfString exception in Powershell version 5.0 (build 10586, revision 117). In a Powershell version 2.0 it works as expected:
$herestr=@"
'"'
"@
Write-Host $herestr
If I quote the last single quote with a backtick (`) the here-string works as expected in both version 2.0 and 5.0.
$herestr=@"
'"`'
"@
Write-Host $herestr
Why do I need to escape the last single quote in a here-string?
BareWord
string literal. And if it failed, then it produce error. You can workaround this by putting extra space:$herestr =@"...
or$herestr= @"...
; or by enclosing in parenthesis:($herestr=@"..."@)
.