0
0
PowerShellscripting~20 mins

Assignment operators in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Assignment 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 script using assignment operators?
Consider the following script. What will be the value of $a after execution?
PowerShell
$a = 10
$a += 5
$a *= 2
$a -= 4
$a
A22
B26
C32
D20
Attempts:
2 left
💡 Hint
Remember to apply each assignment operator step-by-step.
💻 Command Output
intermediate
2:00remaining
What is the output of this script using string assignment operators?
What will be the value of $str after running this script?
PowerShell
$str = 'Hello'
$str += ' World'
$str += '!'
AHello World!
BHelloWorld!
CHello World !
DHello+ World+!
Attempts:
2 left
💡 Hint
The += operator appends strings in PowerShell.
📝 Syntax
advanced
2:00remaining
Which option will cause a syntax error in PowerShell assignment?
Identify the option that will cause a syntax error when run in PowerShell.
A$a = 1; $a -= 1
B$y = 10; $y *= 2
C$x = 5; $x += 3
D$z = 7; $z + = 4
Attempts:
2 left
💡 Hint
Look carefully at the spacing and operator usage.
🚀 Application
advanced
2:00remaining
What is the value of $count after this loop with assignment operators?
Given this script, what is the final value of $count?
PowerShell
$count = 0
for ($i = 1; $i -le 5; $i++) {
  $count += $i
  if ($i % 2 -eq 0) {
    $count -= 1
  }
}
$count
A13
B14
C15
D10
Attempts:
2 left
💡 Hint
Add $i each time, but subtract 1 when $i is even.
🧠 Conceptual
expert
2:00remaining
Which assignment operator will cause an error when used with a $null variable in PowerShell?
Assuming $var is $null, which assignment operation will cause a runtime error?
PowerShell
$var = $null
# Which operation causes error?
A$var += 5
B$var -= 3
C$var /= $null
D$var = 10
Attempts:
2 left
💡 Hint
Think about how PowerShell treats $null with arithmetic operators.