Bird
Raised Fist0
PowerShellscripting~20 mins

Boolean values in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What are the two Boolean values used in PowerShell?
easy
A. $true and $false
B. True and False (without $)
C. 1 and 0
D. Yes and No

Solution

  1. Step 1: Recall PowerShell Boolean syntax

    PowerShell uses special keywords starting with $ for Boolean values.
  2. Step 2: Identify correct Boolean values

    The correct Boolean values are $true and $false, not plain True/False or numbers.
  3. Final Answer:

    $true and $false -> Option A
  4. Quick Check:

    Boolean values = $true, $false [OK]
Hint: Remember PowerShell Booleans start with $ [OK]
Common Mistakes:
  • Using True/False without $
  • Using 1 and 0 as Booleans
  • Confusing Yes/No as Boolean
2. Which of the following is the correct way to assign a Boolean value in PowerShell?
easy
A. $flag = $true
B. $flag = True
C. $flag := $true
D. flag = $true

Solution

  1. Step 1: Check assignment syntax in PowerShell

    PowerShell uses = to assign values to variables, and variables start with $.
  2. Step 2: Identify correct Boolean value and syntax

    The Boolean value must be $true with $ sign, and assignment uses =.
  3. Final Answer:

    $flag = $true -> Option A
  4. Quick Check:

    Assign Boolean with $true and = [OK]
Hint: Use $true with = for Boolean assignment [OK]
Common Mistakes:
  • Missing $ on Boolean value
  • Using := instead of =
  • Missing $ on variable name
3. What will this PowerShell code output?
if ($false) { "Yes" } else { "No" }
medium
A. $false
B. Yes
C. No
D. Error

Solution

  1. Step 1: Understand the if condition

    The condition is $false, which means the if block will NOT run.
  2. Step 2: Determine which block runs

    Since the if condition is false, the else block runs and outputs "No".
  3. Final Answer:

    No -> Option C
  4. Quick Check:

    if $false runs else block = No [OK]
Hint: If condition false runs else block [OK]
Common Mistakes:
  • Thinking $false runs if block
  • Expecting output $false instead of string
  • Confusing syntax causing error
4. Identify the error in this PowerShell snippet:
if ($True) { Write-Output "Yes" } else { Write-Output "No" }
medium
A. Boolean values must be lowercase: $true, $false
B. Missing parentheses around condition
C. Write-Output is not valid in if blocks
D. No error, code runs fine

Solution

  1. Step 1: Check Boolean case sensitivity

    PowerShell Boolean values are case-insensitive, so $True works like $true.
  2. Step 2: Verify syntax correctness

    The if statement syntax is correct with parentheses and Write-Output is valid.
  3. Final Answer:

    No error, code runs fine -> Option D
  4. Quick Check:

    PowerShell Booleans are case-insensitive [OK]
Hint: PowerShell Booleans ignore case [OK]
Common Mistakes:
  • Thinking $True is invalid case
  • Expecting syntax error without parentheses
  • Believing Write-Output can't be used here
5. You want to run a script block only if a variable $isReady is true. Which is the best way to check this in PowerShell?
hard
A. if ($isReady -eq $true) { ... }
B. All of the above
C. if ($isReady -ne $false) { ... }
D. if ($isReady) { ... }

Solution

  1. Step 1: Understand Boolean checks in PowerShell

    PowerShell treats variables as Boolean in if conditions directly, so if ($isReady) works.
  2. Step 2: Analyze other comparisons

    Checking explicitly with -eq $true or -ne $false also works to test if $isReady is true.
  3. Step 3: Confirm all options are valid

    All three ways correctly check if $isReady is true and run the block.
  4. Final Answer:

    All of the above -> Option B
  5. Quick Check:

    Multiple ways to test Boolean true in PowerShell [OK]
Hint: You can test Booleans directly or with -eq/-ne [OK]
Common Mistakes:
  • Thinking only direct if ($isReady) works
  • Confusing -eq $true with assignment
  • Ignoring that -ne $false also works
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard