Bird
0
0

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📝 Application Q15 of 15
PowerShell - Variables and Data Types
You want to run a script block only if a variable $isReady is true. Which is the best way to check this in PowerShell?
Aif ($isReady -eq $true) { <code>...</code> }
BAll of the above
Cif ($isReady -ne $false) { <code>...</code> }
Dif ($isReady) { <code>...</code> }
Step-by-Step Solution
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]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes