Bird
0
0

You want to write a script that checks if the 'W32Time' service is stopped, and if so, starts it. Which script snippet correctly does this?

hard📝 Application Q15 of 15
PowerShell - System Administration
You want to write a script that checks if the 'W32Time' service is stopped, and if so, starts it. Which script snippet correctly does this?
A<pre>Start-Service -Name W32Time -IfStopped</pre>
B<pre>if (Get-Service W32Time -Status 'Stopped') { Start-Service W32Time }</pre>
C<pre>$svc = Get-Service -Name W32Time if ($svc.Status -eq 'Stopped') { Start-Service -Name W32Time }</pre>
D<pre>$svc = Get-Service W32Time if ($svc.Status = 'Stopped') { Start-Service W32Time }</pre>
Step-by-Step Solution
Solution:
  1. Step 1: Retrieve the service object and check status

    Using $svc = Get-Service -Name W32Time stores the service object. Then $svc.Status -eq 'Stopped' correctly compares the status.
  2. Step 2: Start the service if stopped

    If the status is 'Stopped', Start-Service -Name W32Time starts the service.
  3. Final Answer:

    $svc = Get-Service -Name W32Time if ($svc.Status -eq 'Stopped') { Start-Service -Name W32Time } -> Option C
  4. Quick Check:

    Check status with -eq, then start service [OK]
Quick Trick: Use -eq to compare status, then Start-Service if stopped [OK]
Common Mistakes:
  • Using single = instead of -eq for comparison
  • Assuming Start-Service has -IfStopped parameter
  • Trying to filter Get-Service with -Status parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes