Bird
0
0

You want to create a PowerShell monitoring script that checks CPU usage every 5 minutes and sends an email alert if usage exceeds 80%. Which approach correctly implements this?

hard📝 Best Practice Q15 of 15
PowerShell - Automation Patterns
You want to create a PowerShell monitoring script that checks CPU usage every 5 minutes and sends an email alert if usage exceeds 80%. Which approach correctly implements this?
AUse a loop with Start-Sleep 300, check CPU with Get-Counter, send email if over 80%
BRun Get-Counter once, then send email immediately without looping
CUse a scheduled task to run the script every hour, check CPU, send email if over 80%
DUse a loop with Start-Sleep 60, check CPU once, then exit
Step-by-Step Solution
Solution:
  1. Step 1: Understand monitoring frequency

    Checking CPU every 5 minutes requires a loop with a 300-second (5-minute) sleep between checks.
  2. Step 2: Use Get-Counter and conditional email

    Get-Counter can measure CPU usage; if usage > 80%, Send-MailMessage sends alert.
  3. Step 3: Evaluate options

    Use a loop with Start-Sleep 300, check CPU with Get-Counter, send email if over 80% uses loop with Start-Sleep 300 and conditional email, matching requirements. Others either run once or wrong intervals.
  4. Final Answer:

    Use a loop with Start-Sleep 300, check CPU with Get-Counter, send email if over 80% -> Option A
  5. Quick Check:

    Loop + 5 min sleep + CPU check + email = C [OK]
Quick Trick: Loop with 300s sleep and conditional email alert [OK]
Common Mistakes:
  • Running check only once without loop
  • Using wrong sleep duration
  • Confusing scheduled task frequency with script loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes