The -and operator returns $true only if both conditions on its sides are true. It works like saying "and" in everyday language, meaning both things must happen.
Click to reveal answer
beginner
How does the -or operator work in PowerShell?
The -or operator returns $true if at least one of the conditions is true. It means "or" in normal talk, so if either side is true, the whole expression is true.
Click to reveal answer
beginner
Explain the purpose of the -not operator in PowerShell.
The -not operator reverses the truth value of a condition. If something is $true, -not makes it $false, and vice versa. It's like saying "not" in everyday language.
Click to reveal answer
beginner
What will this PowerShell expression return? $true -and $false
It will return $false because -and needs both sides to be $true. Here, one side is $false, so the whole result is $false.
Click to reveal answer
intermediate
What is the result of this expression? -not ($false -or $false)
The expression inside the parentheses ($false -or $false) is $false. Then -not reverses it to $true. So the final result is $true.
Click to reveal answer
Which operator returns $true only if both conditions are true?
A-or
B-and
C-not
D==
✗ Incorrect
The -and operator requires both sides to be true to return $true.
What does -not $true return?
A$true
BError
C$false
Dnull
✗ Incorrect
-not reverses the value, so -not $true is $false.
If $a = $false and $b = $true, what is the result of $a -or $b?
A$true
Bnull
C$false
DError
✗ Incorrect
The -or operator returns $true if at least one side is true.
Which operator would you use to check if a condition is NOT true?
A-not
B-and
C-or
D-eq
✗ Incorrect
-not is used to reverse the truth value of a condition.
What is the result of $true -and ($false -or $true)?
AError
B$false
Cnull
D$true
✗ Incorrect
Inside parentheses $false -or $true is $true, so $true -and $true is $true.
Explain how the -and, -or, and -not operators work in PowerShell with simple examples.
Think about how you use 'and', 'or', and 'not' in everyday sentences.
You got /4 concepts.
Describe a real-life situation where you might use -and and -or in a PowerShell script.
Imagine checking if you can go outside based on weather and time.
You got /4 concepts.
Practice
(1/5)
1. Which logical operator in PowerShell means both conditions must be true for the whole expression to be true?
easy
A. -xor
B. -or
C. -and
D. -not
Solution
Step 1: Understand the meaning of -and
The -and operator requires both conditions to be true for the entire expression to be true.
Step 2: Compare with other operators
-or means one or both conditions true; -not reverses a condition; -xor means exactly one true.
Final Answer:
-and -> Option C
Quick Check:
-and = both true [OK]
Hint: Remember: -and means both must be true [OK]
Common Mistakes:
Confusing -and with -or
Thinking -not means both true
Mixing -and with -xor
2. Which of the following is the correct syntax to check if variable $a is greater than 5 AND $b is less than 10 in PowerShell?
easy
A. if ($a -gt 5 && $b -lt 10) { Write-Output 'true' }
B. if ($a -gt 5 -and $b -lt 10) { Write-Output 'true' }
C. if ($a > 5 && $b < 10) { Write-Output 'true' }
D. if ($a > 5 -and $b < 10) { Write-Output 'true' }