0
0
PowerShellscripting~20 mins

Boolean values in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Boolean Mastery in PowerShell
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 PowerShell script:
$a = $true
$b = $false
$result = $a -and $b
Write-Output $result

What will be printed?
PowerShell
$a = $true
$b = $false
$result = $a -and $b
Write-Output $result
AFalse
BTrue
C1
D0
Attempts:
2 left
💡 Hint
Remember that -and returns True only if both sides are True.
💻 Command Output
intermediate
2:00remaining
What does this PowerShell expression output?
What is the output of this code?
Write-Output ($false -or $true)
PowerShell
Write-Output ($false -or $true)
AFalse
BTrue
C0
D1
Attempts:
2 left
💡 Hint
The -or operator returns True if at least one operand is True.
📝 Syntax
advanced
2:00remaining
Which option correctly assigns a Boolean value in PowerShell?
Which of the following lines correctly assigns a Boolean True value to the variable $flag?
A$flag = True
B$flag = TRUE
C$flag = $True
D$flag = true
Attempts:
2 left
💡 Hint
PowerShell Boolean constants start with a dollar sign and capital T.
🚀 Application
advanced
2:00remaining
What is the output of this conditional check?
Given this script:
$value = 0
if ($value) { Write-Output 'Yes' } else { Write-Output 'No' }

What will it print?
PowerShell
$value = 0
if ($value) { Write-Output 'Yes' } else { Write-Output 'No' }
AYes
BTrue
C0
DNo
Attempts:
2 left
💡 Hint
In PowerShell, non-null values are treated as True in conditionals.
🧠 Conceptual
expert
2:00remaining
What error does this PowerShell script raise?
What error will this script produce?
$x = 'True'
if ($x -eq $True) { Write-Output 'Match' } else { Write-Output 'No Match' }
PowerShell
$x = 'True'
if ($x -eq $True) { Write-Output 'Match' } else { Write-Output 'No Match' }
ANo error, outputs 'No Match'
BNo error, outputs 'Match'
CTypeMismatchException
DRuntime error: Invalid comparison
Attempts:
2 left
💡 Hint
Check how PowerShell compares strings and Booleans.