A. No output because Send-MailMessage blocks output
B. 'Alert sent' if Notepad is not running, else 'Notepad is running'
C. Syntax error due to missing parentheses
D. Always 'Alert sent' regardless of Notepad status
Solution
Step 1: Understand the condition
The script checks if Notepad process exists; if not found, condition is true.
Step 2: Analyze the if-else branches
If Notepad is not running, it sends an email and outputs 'Alert sent'. Otherwise, outputs 'Notepad is running'.
Final Answer:
'Alert sent' if Notepad is not running, else 'Notepad is running' -> Option B
Quick Check:
Process check controls output [OK]
Hint: Check process null means send alert, else normal message [OK]
Common Mistakes:
Assuming Send-MailMessage blocks output
Thinking condition always true
Confusing error handling with syntax error
4. You wrote this script to send an email alert if disk space is low:
$freeSpace = (Get-PSDrive C).Free
if ($freeSpace -lt "100MB") {
Send-MailMessage -From 'alert@example.com' -To 'admin@example.com' -Subject 'Low Disk Space' -Body 'Disk space below 100MB' -SmtpServer 'smtp.example.com'
}
But no email is sent even when disk space is low. What is the likely problem?
medium
A. The if condition should use -gt instead of -lt
B. Get-PSDrive does not return Free space
C. Send-MailMessage requires -Port parameter
D. 100MB is not a valid size unit in PowerShell comparison
Solution
Step 1: Check the size comparison
PowerShell does not recognize '100MB' as a valid number; it must be converted to bytes.
Step 2: Understand Get-PSDrive output
Get-PSDrive returns Free space in bytes as a number, so comparing to '100MB' string fails silently.
Final Answer:
100MB is not a valid size unit in PowerShell comparison -> Option D
Quick Check:
Size units must be numeric bytes [OK]
Hint: Use numeric bytes, not '100MB' string in comparisons [OK]
Common Mistakes:
Assuming Get-PSDrive Free is not available
Thinking Send-MailMessage needs -Port always
Confusing less than and greater than operators
5. 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
A. Use a loop with Start-Sleep 300, check CPU with Get-Counter, send email if over 80%
B. Run Get-Counter once, then send email immediately without looping
C. Use a scheduled task to run the script every hour, check CPU, send email if over 80%
D. Use a loop with Start-Sleep 60, check CPU once, then exit
Solution
Step 1: Understand monitoring frequency
Checking CPU every 5 minutes requires a loop with a 300-second (5-minute) sleep between checks.
Step 2: Use Get-Counter and conditional email
Get-Counter can measure CPU usage; if usage > 80%, Send-MailMessage sends alert.
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.
Final Answer:
Use a loop with Start-Sleep 300, check CPU with Get-Counter, send email if over 80% -> Option A
Quick Check:
Loop + 5 min sleep + CPU check + email = C [OK]
Hint: 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
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.