A here-string is a way to create multiline strings easily. It starts with @" and ends with "@ for double-quoted strings, or @' and '@ for single-quoted strings.
Click to reveal answer
beginner
How do you start and end a double-quoted here-string in PowerShell?
Start with @" on a new line and end with "@ on a new line. Everything between is part of the string, including line breaks.
Click to reveal answer
intermediate
What is the difference between single-quoted and double-quoted here-strings?
Double-quoted here-strings allow variable expansion and escape sequences. Single-quoted here-strings treat content literally, no variable expansion.
Click to reveal answer
beginner
Show a simple example of a here-string that contains multiple lines.
Example:
$myString = @"
Line one
Line two
Line three
"@
This stores three lines in $myString.
Click to reveal answer
beginner
Why are here-strings useful in scripting?
They let you write long text blocks or scripts inside a variable without worrying about quotes or line breaks. This makes scripts easier to read and maintain.
Click to reveal answer
How do you start a double-quoted here-string in PowerShell?
A"@
B@"
C@'
D'@
✗ Incorrect
A double-quoted here-string starts with @" on a new line.
Which here-string type allows variable expansion?
ADouble-quoted here-string
BSingle-quoted here-string
CBoth single and double-quoted here-strings
DNeither
✗ Incorrect
Double-quoted here-strings allow variables inside the string to be replaced with their values.
What symbol ends a single-quoted here-string?
A'@
B@"
C"@
D@'
✗ Incorrect
A single-quoted here-string ends with '@ on a new line.
Which of these is a correct here-string assignment?
A$text = @"
Hello
World
"@
B$text = @'
Hello
World
'@
CBoth A and C
D$text = "Hello
World"
✗ Incorrect
Both A and C are valid here-string assignments; A is double-quoted, C is single-quoted.
Why use here-strings instead of normal strings for multiline text?
AHere-strings automatically trim spaces
BHere-strings do not support variables
CHere-strings are faster to execute
DHere-strings allow multiline text without escape characters
✗ Incorrect
Here-strings let you write multiline text easily without needing escape characters for new lines.
Explain how to create a multiline string using here-strings in PowerShell.
Think about how you open and close the string and what happens inside.
You got /4 concepts.
Describe the difference between single-quoted and double-quoted here-strings and when you might use each.
Consider how variables behave inside each type.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using a here-string in PowerShell?
easy
A. To execute multiple commands in one line
B. To create multiline strings preserving formatting and line breaks
C. To define a function with multiple parameters
D. To comment out multiple lines of code
Solution
Step 1: Understand what a here-string is
A here-string is a way to write text that spans multiple lines without losing formatting or line breaks.
Step 2: Compare options with the definition
Only To create multiline strings preserving formatting and line breaks correctly describes the purpose of here-strings in PowerShell.
Final Answer:
To create multiline strings preserving formatting and line breaks -> Option B
Quick Check:
Here-strings = multiline text [OK]
Hint: Here-strings keep text exactly as typed across lines [OK]
Common Mistakes:
Confusing here-strings with command execution
Thinking here-strings are for comments
Assuming here-strings define functions
2. Which of the following is the correct syntax to start a double-quoted here-string in PowerShell?
easy
A. @' (at sign followed by single quote)
B. "@ (double quote followed by at sign)
C. @ (at sign followed by double quote)
D. @" (at sign followed by double quote)
Solution
Step 1: Recall here-string syntax
Double-quoted here-strings start with @" and end with "@.
Step 2: Match options with syntax
@" (at sign followed by double quote) correctly shows @" as the start of a double-quoted here-string.
Final Answer:
@" -> Option D
Quick Check:
Double-quoted here-string start = @" [OK]
Hint: Double-quoted here-strings start with @" [OK]
Common Mistakes:
Using single quote instead of double quote for double-quoted here-string
Reversing the order of @ and "
Confusing start and end delimiters
3. What will be the output of this PowerShell code?
5. You want to create a multiline string in PowerShell that includes the literal text "$path" without expanding it, but also includes a variable $user expanded. Which here-string syntax should you use?
hard
A. Use double-quoted here-string @" ... "@ and escape $path as `$path
B. Use single-quoted here-string @' ... '@ and write $user outside it
C. Use double-quoted here-string @" ... "@ and write $path as is
D. Use single-quoted here-string @' ... '@ and include $user inside it
Solution
Step 1: Understand variable expansion in here-strings
Double-quoted here-strings expand variables, single-quoted do not.
Step 2: Requirement analysis
You want $user expanded but $path literal. So use double-quoted here-string and escape $path as `$path to prevent expansion.
Final Answer:
Use double-quoted here-string @" ... "@ and escape $path as `$path -> Option A
Quick Check:
Escape variables to keep literal in double-quoted here-strings [OK]
Hint: Escape $ with backtick to keep literal in double-quoted here-strings [OK]
Common Mistakes:
Using single-quoted here-string disables all variable expansion
Not escaping $path causes unwanted expansion
Trying to expand variables inside single-quoted here-string
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.