Bird
0
0

Why does this script fail to send an email?

medium📝 Troubleshoot Q7 of 15
PowerShell - Automation Patterns
Why does this script fail to send an email?
$disk = Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" | Where-Object { $_.FreeSpace -lt 1000000000 } if ($disk) { Send-MailMessage -To 'admin@example.com' -Subject 'Low Disk Space' -Body 'Disk space is low' -SmtpServer 'smtp.example.com' }
AFreeSpace property is not numeric
BIncorrect filter syntax in Get-WmiObject
CSend-MailMessage requires -From parameter
DMissing semicolon or newline between pipeline and if statement
Step-by-Step Solution
Solution:
  1. Step 1: Check script structure

    Pipeline ends without separator before if statement, causing syntax error.
  2. Step 2: Confirm other parts

    Filter syntax is correct, -From is optional, FreeSpace is numeric.
  3. Final Answer:

    Missing semicolon or newline between pipeline and if statement -> Option D
  4. Quick Check:

    Proper statement separation needed [OK]
Quick Trick: Separate statements with semicolon or newline [OK]
Common Mistakes:
  • Not separating pipeline and if statement
  • Assuming -From is mandatory
  • Misunderstanding filter syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes