Bird
0
0

In PowerShell, which of the following expressions correctly checks if the variable $value is greater than or equal to 10 and less than or equal to 20?

hard📝 Application Q8 of 15
PowerShell - Operators
In PowerShell, which of the following expressions correctly checks if the variable $value is greater than or equal to 10 and less than or equal to 20?
A$value -gt 10 -and $value -lt 20
B($value -ge 10) -and ($value -le 20)
C$value -ge 10 -or $value -le 20
D$value -gt 10 -or $value -lt 20
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range check

    We want to check if $value is between 10 and 20 inclusive, so it should be greater than or equal to 10 and less than or equal to 20.
  2. Step 2: Identify correct operators

    Use '-ge' for greater than or equal and '-le' for less than or equal. Combine with '-and' to ensure both conditions are true.
  3. Final Answer:

    ($value -ge 10) -and ($value -le 20) -> Option B
  4. Quick Check:

    Both comparisons use inclusive operators and are combined with '-and' [OK]
Quick Trick: Use '-ge' and '-le' with '-and' for inclusive range checks [OK]
Common Mistakes:
  • Using '-gt' and '-lt' excludes boundary values
  • Using '-or' instead of '-and' allows values outside the range
  • Mixing assignment '=' instead of comparison operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes