0
0
PowerShellscripting~20 mins

Here-strings for multiline in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Here-strings Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell here-string?
Consider the following PowerShell script using a here-string. What will be the exact output when this script runs?
PowerShell
$text = @"
Hello,
This is a multiline
string.
"@
Write-Output $text
A
Hello,
This is a multiline
string.
BHello, This is a multiline string.
C"Hello,\nThis is a multiline\nstring."
DHello,This is a multilinestring.
Attempts:
2 left
💡 Hint
Remember that here-strings preserve line breaks exactly as typed.
📝 Syntax
intermediate
2:00remaining
Which option correctly defines a here-string in PowerShell?
Select the option that correctly creates a multiline string using a here-string in PowerShell.
A
$str = @"
Line 1
Line 2
'
B
$str = @"
Line 1
Line 2
"@
C
$str = @'
Line 1
Line 2
"@
D
$str = '@
Line 1
Line 2
@'
Attempts:
2 left
💡 Hint
Here-strings start with @" and end with "@ or start with @' and end with '@ but must match.
🔧 Debug
advanced
2:00remaining
Why does this here-string cause an error?
This PowerShell code throws an error. What is the cause?
PowerShell
$text = @"
This is a test
  "@
Write-Output $text
AThe closing delimiter "@" must be alone on its line with no spaces.
BHere-strings cannot contain the word 'test'.
CThe opening delimiter @" is missing a closing quote.
DWrite-Output cannot print here-strings.
Attempts:
2 left
💡 Hint
Check how the closing delimiter is placed in the code.
🚀 Application
advanced
2:00remaining
How to include variables inside a here-string?
Given $name = "Alice", which here-string will correctly include the variable's value in the output?
PowerShell
$name = "Alice"
$text = @?
Hello, $name!
Welcome.
?@
Write-Output $text
A
$text = @'
Hello, " + $name + "!
Welcome.
'@
B
$text = @'
Hello, $name!
Welcome.
'@
C
$text = @"
Hello, '$name'!
Welcome.
"@
D
$text = @"
Hello, $name!
Welcome.
"@
Attempts:
2 left
💡 Hint
Double-quoted here-strings allow variable expansion, single-quoted do not.
🧠 Conceptual
expert
2:00remaining
What is the number of lines in the output of this here-string?
How many lines will the following PowerShell script output?
PowerShell
$text = @"
Line1

Line3
Line4
"@
Write-Output $text | Measure-Object -Line
A4
B3
C5
D6
Attempts:
2 left
💡 Hint
Count all lines including empty ones preserved by the here-string.