Bird
0
0

What happens when this PowerShell script runs?

medium📝 Command Output Q4 of 15
PowerShell - Automation Patterns
What happens when this PowerShell script runs?
if (-not (Get-Service -Name 'Spooler' -ErrorAction SilentlyContinue).Status -eq 'Running') { Send-MailMessage -To 'admin@example.com' -Subject 'Service Alert' -Body 'Print Spooler service is stopped.' -SmtpServer 'smtp.example.com' }
AStarts the Print Spooler service automatically
BSends an email alert if the Print Spooler service is not running
CLogs the service status to a file without sending email
DThrows an error if the service is running
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the condition

    The script checks if the 'Spooler' service is not running.
  2. Step 2: Understand the action

    If the service is stopped, it sends an email alert.
  3. Final Answer:

    Sends an email alert if the Print Spooler service is not running -> Option B
  4. Quick Check:

    Condition triggers email alert [OK]
Quick Trick: Email sent only if service is stopped [OK]
Common Mistakes:
  • Assuming the script starts the service
  • Thinking it logs status instead of emailing
  • Believing it errors when service is running

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes