The -eq operator checks if two values are equal. It returns True if they are the same, otherwise False.
Click to reveal answer
beginner
Explain the use of -ne in PowerShell.
The -ne operator means 'not equal'. It returns True if two values are different, and False if they are the same.
Click to reveal answer
beginner
What is the difference between -gt and -lt in PowerShell?
-gt means 'greater than' and checks if the left value is bigger than the right. -lt means 'less than' and checks if the left value is smaller than the right.
Click to reveal answer
beginner
How would you check if a variable $x is greater than 10 in PowerShell?
Use the operator -gt: $x -gt 10. This returns True if $x is more than 10.
Click to reveal answer
beginner
What will 5 -lt 3 return in PowerShell and why?
It returns False because 5 is not less than 3.
Click to reveal answer
Which operator checks if two values are NOT equal in PowerShell?
A-eq
B-gt
C-ne
D-lt
✗ Incorrect
The -ne operator means 'not equal' and returns True if values differ.
What does 7 -gt 5 return?
ANull
BTrue
CError
DFalse
✗ Incorrect
-gt means 'greater than'. 7 is greater than 5, so it returns True.
If $a = 4 and $b = 4, what does $a -eq $b return?
ATrue
BFalse
CNull
DError
✗ Incorrect
Since both values are equal, -eq returns True.
Which operator would you use to check if a number is less than another?
A-ne
B-gt
C-eq
D-lt
✗ Incorrect
-lt means 'less than' and checks if left value is smaller.
What does 10 -ne 10 return?
AFalse
BTrue
CError
DNull
✗ Incorrect
Since both values are equal, -ne returns False.
Describe how to use PowerShell comparison operators to compare two numbers.
Think about how you compare numbers in daily life: equal, not equal, bigger, smaller.
You got /4 concepts.
Give an example of a PowerShell command using -gt and explain what it does.
Imagine checking if your age is greater than 18.
You got /3 concepts.
Practice
(1/5)
1. Which PowerShell operator checks if two values are equal?
easy
A. -eq
B. -ne
C. -gt
D. -lt
Solution
Step 1: Understand the meaning of each operator
-eq means equals, -ne means not equals, -gt means greater than, -lt means less than.
Step 2: Identify the operator for equality
The operator that checks if two values are equal is -eq.
Final Answer:
-eq -> Option A
Quick Check:
Equals operator = -eq [OK]
Hint: Remember: eq means equal, ne means not equal [OK]
Common Mistakes:
Confusing -eq with -ne
Mixing -gt and -lt
Using == instead of -eq
2. Which of the following is the correct syntax to check if variable $a is greater than 10 in PowerShell?
easy
A. if ($a -gt 10) { }
B. if ($a > 10) { }
C. if ($a -lt 10) { }
D. if ($a -eq 10) { }
Solution
Step 1: Recall PowerShell comparison syntax
PowerShell uses -gt for greater than, not > like some other languages.
Step 2: Match the correct operator
The correct syntax to check if $a is greater than 10 is if ($a -gt 10) { }.
Final Answer:
if ($a -gt 10) { } -> Option A
Quick Check:
Greater than operator = -gt [OK]
Hint: Use -gt for greater than, not > in PowerShell [OK]
Common Mistakes:
Using > instead of -gt
Confusing -lt with -gt
Missing parentheses in if statement
3. What will be the output of this PowerShell code?
$x = 5 if ($x -ne 5) { 'No' } else { 'Yes' }
medium
A. 5
B. No
C. Yes
D. False
Solution
Step 1: Evaluate the condition $x -ne 5
$x is 5, so $x -ne 5 means 5 not equal to 5, which is False.
Step 2: Determine which block runs
Since condition is False, the else block runs, outputting 'Yes'.
Final Answer:
Yes -> Option C
Quick Check:
5 not equal 5 is False, so else runs [OK]
Hint: -ne means not equal; false triggers else block [OK]
PowerShell supports elseif as one word; braces are balanced.
Step 2: Verify operators and structure
-gt and -lt are correct operators; no syntax errors present.
Final Answer:
No error, code runs correctly -> Option B
Quick Check:
elseif is valid in PowerShell [OK]
Hint: PowerShell uses elseif as one word, not else if [OK]
Common Mistakes:
Thinking elseif is invalid
Expecting > instead of -gt
Missing braces confusion
5. You want to write a PowerShell script that prints 'Valid' only if a variable $score is greater than or equal to 70. Which code snippet correctly uses comparison operators to achieve this?
hard
A. if ($score -gt 70) { 'Valid' } else { 'Invalid' }
B. if ($score -lt 70) { 'Valid' } else { 'Invalid' }
C. if ($score -eq 70) { 'Valid' } else { 'Invalid' }
D. if ($score -ge 70) { 'Valid' } else { 'Invalid' }
Solution
Step 1: Understand the requirement
We want to check if $score is greater than or equal to 70.
Step 2: Identify the correct operator
-ge means greater than or equal to, which matches the requirement.
Final Answer:
if ($score -ge 70) { 'Valid' } else { 'Invalid' } -> Option D
Quick Check:
Greater or equal operator = -ge [OK]
Hint: Use -ge for greater or equal comparisons [OK]
Common Mistakes:
Using -gt excludes 70
Using -eq only matches exactly 70
Using -lt reverses logic
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.