0
0
PowerShellscripting~5 mins

Boolean values in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are Boolean values in PowerShell?
Boolean values represent two states: True or False. They are used to control logic and decisions in scripts.
Click to reveal answer
beginner
How do you assign a Boolean value to a variable in PowerShell?
You assign it like this: $isReady = $true or $isDone = $false. Use $true and $false keywords.
Click to reveal answer
beginner
What will this PowerShell code output?<br>
$a = $true<br>if ($a) { 'Yes' } else { 'No' }
It will output Yes because the variable $a is $true, so the if condition passes.
Click to reveal answer
beginner
Can Boolean values be used directly in conditions in PowerShell? Explain.
Yes, Boolean values like $true or $false can be used directly in if or while conditions to control flow.
Click to reveal answer
intermediate
What is the difference between $true and 1 in PowerShell?
$true is a Boolean value representing true. 1 is a number. PowerShell treats $true as 1 in numeric context but they are different types.
Click to reveal answer
Which keyword represents a true Boolean value in PowerShell?
ATRUE
BTrue
C$true
D1
What will this code output?<br>
$flag = $false<br>if (-not $flag) { 'No' } else { 'Yes' }
ANo
BNothing
CError
DYes
Which of these is NOT a valid Boolean value in PowerShell?
A$true
B$false
C$True
DTrue
How do you check if a variable $x is true in PowerShell?
Aif ($x -eq $true)
BBoth A and C
Cif ($x)
Dif ($x == true)
What type of value is $true in PowerShell?
ABoolean
BInteger
CString
DNull
Explain how Boolean values control the flow of a PowerShell script.
Think about how scripts decide what to do next.
You got /5 concepts.
    Describe how to assign and use Boolean variables in PowerShell with an example.
    Show a simple script snippet.
    You got /4 concepts.