A here-string starts with @" or @' and ends with "@ or '@ to hold multiple lines as one string.
Execution Sample
PowerShell
$text = @"
Line 1
Line 2
Line 3
"@
Write-Output $text
This code stores three lines in a variable using a here-string and then prints it.
Execution Table
Step
Action
Value of $text
Output
1
Start here-string with @" delimiter
""
2
Add line: Line 1
"Line 1\n"
3
Add line: Line 2
"Line 1\nLine 2\n"
4
Add line: Line 3
"Line 1\nLine 2\nLine 3\n"
5
End here-string with "@ delimiter
"Line 1\nLine 2\nLine 3\n"
6
Write-Output $text
"Line 1\nLine 2\nLine 3\n"
Line 1
Line 2
Line 3
💡 Here-string ends at "@ delimiter; output shows multiline string.
Variable Tracker
Variable
Start
After Step 2
After Step 3
After Step 4
After Step 5
Final
$text
null
"Line 1\n"
"Line 1\nLine 2\n"
"Line 1\nLine 2\nLine 3\n"
"Line 1\nLine 2\nLine 3\n"
"Line 1\nLine 2\nLine 3\n"
Key Moments - 3 Insights
Why do we use @" and "@ instead of quotes for multiline strings?
Because normal quotes can't hold multiple lines easily; here-strings let you write many lines without special characters, as shown in execution_table steps 1 and 5.
Does the here-string keep the line breaks inside the string?
Yes, each line break is preserved inside the string, so output shows multiple lines (see execution_table step 6 output).
Can we use single quotes instead of double quotes for here-strings?
Yes, single-quoted here-strings (@' '@) treat content literally without variable expansion, but double-quoted (@" "@) allow variables inside. This example uses double quotes.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4. What is the value of $text?
A"Line 1\nLine 2\n"
B"Line 1\n"
C"Line 1\nLine 2\nLine 3\n"
D""
💡 Hint
Check the 'Value of $text' column at step 4 in execution_table.
At which step does the here-string end?
AStep 3
BStep 5
CStep 6
DStep 2
💡 Hint
Look for the action 'End here-string with "@ delimiter' in execution_table.
If we replaced @" and "@ with single quotes @' and '@, what would change?
AVariable expansion inside the string would not happen
BThe string would not keep line breaks
CThe here-string would be invalid
DThe output would be on one line
💡 Hint
Recall key_moments about difference between single and double quoted here-strings.
Concept Snapshot
Here-strings hold multiline text in PowerShell.
Start with @" and end with "@ for double-quoted strings.
Preserves line breaks and supports variables.
Use @' and '@ for literal strings without variable expansion.
Assign to variables or output directly.
Full Transcript
This visual shows how PowerShell here-strings work. We start a here-string with @" and write multiple lines. Each line adds to the variable $text. We end the here-string with "@. The variable keeps all lines with line breaks. When we output $text, it prints all lines exactly as typed. Here-strings are useful for storing or printing multiline text easily. Single-quoted here-strings (@' '@) keep text literal without expanding variables. Double-quoted here-strings (@" "@) allow variables inside. This example uses double quotes. The execution table tracks each step of building the string and the final output.