0
0
PowerShellscripting~20 mins

String interpolation (double quotes) in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell String Interpolation 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 code with string interpolation?
Consider the following PowerShell script. What will it output?
PowerShell
$name = "Alice"
$age = 30
Write-Output "My name is $name and I am $age years old."
AMy name is $name and I am $age years old.
BMy name is Alice and I am 30 years old.
CMy name is and I am years old.
DMy name is $($name) and I am $($age) years old.
Attempts:
2 left
💡 Hint
In PowerShell, variables inside double quotes are replaced by their values.
💻 Command Output
intermediate
2:00remaining
What does this PowerShell code output when using nested expressions in double quotes?
Look at this script and choose the correct output:
PowerShell
$count = 5
Write-Output "There are $($count + 3) items."
AThere are 8 items.
BThere are $count + 3 items.
CThere are 53 items.
DThere are $($count + 3) items.
Attempts:
2 left
💡 Hint
The $() syntax evaluates the expression inside the parentheses.
💻 Command Output
advanced
2:00remaining
What is the output of this PowerShell string interpolation with a file path?
What will this script output?
PowerShell
$path = "C:\Program Files\App"
Write-Output "The path is: $path"
AThe path is: C:\Program Files\App
BThe path is: $path
CThe path is: C:Program FilesApp
DppAseliF margorP:C :si htap ehT
Attempts:
2 left
💡 Hint
Backslashes are literal characters in PowerShell double-quoted strings.
🚀 Application
advanced
2:00remaining
How many items are in the array after this PowerShell script runs?
Given this script, how many items does $results contain?
PowerShell
$results = @()
for ($i = 1; $i -le 3; $i++) {
  $results += "Item $i"
}
$results
A0
B1
C3
D4
Attempts:
2 left
💡 Hint
Each loop adds one string to the array.
🧠 Conceptual
expert
2:00remaining
What error does this PowerShell script raise?
What error will this script produce when run?
PowerShell
$value = 10
Write-Output "Result: $value + 5"
ASyntax error: Unexpected token '+'
BNo error, outputs: Result: 15
CRuntime error: Invalid expression
DNo error, outputs: Result: 10 + 5
Attempts:
2 left
💡 Hint
Check how PowerShell treats expressions inside double quotes without $()