0
0
PowerShellscripting~20 mins

Variable creation with $ in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Variable 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?
Consider the following script:
$name = "Alice"
Write-Output $name
What will be printed when this script runs?
PowerShell
$name = "Alice"
Write-Output $name
AWrite-Output Alice
B$name
CAlice
DError: Variable not defined
Attempts:
2 left
💡 Hint
Variables in PowerShell start with $. The Write-Output command prints the value of the variable.
📝 Syntax
intermediate
2:00remaining
Which option correctly creates a variable with the value 10?
In PowerShell, you want to create a variable named $count with the number 10. Which line is correct?
A$count := 10
B$count = 10
Ccount = $10
Dlet $count = 10
Attempts:
2 left
💡 Hint
PowerShell uses = to assign values to variables starting with $.
🔧 Debug
advanced
2:00remaining
What error does this code produce?
Look at this script:
name = "Bob"
Write-Output $name
What error will occur when running it?
PowerShell
name = "Bob"
Write-Output $name
AError: Variable 'name' is not recognized because it lacks $
BOutputs: Bob
CError: Write-Output is not a recognized command
DOutputs: $name
Attempts:
2 left
💡 Hint
In PowerShell, variables must start with $.
🚀 Application
advanced
2:00remaining
How many variables are created after running this script?
Consider this script:
$a = 5
$b = $a
$c = $b + 10
How many variables exist after running it?
PowerShell
$a = 5
$b = $a
$c = $b + 10
A1
B0
C2
D3
Attempts:
2 left
💡 Hint
Each line creates or assigns a variable starting with $.
🧠 Conceptual
expert
2:00remaining
Which option best describes variable naming rules in PowerShell?
Choose the correct statement about variable names in PowerShell.
AVariable names must start with $ and can include letters, numbers, and underscores; they are case-insensitive.
BVariable names must start with $ and only contain letters; numbers are not allowed.
CVariable names can start with any character and are case-sensitive.
DVariable names must start with a letter or underscore and are case-insensitive.
Attempts:
2 left
💡 Hint
Remember that $ is part of the variable name syntax in PowerShell.