0
0
PowerShellscripting~20 mins

Service management (Get/Start/Stop-Service) in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Service Management Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell command?
Consider the following command run on a Windows machine with a service named 'wuauserv' (Windows Update service). What will be the output type of this command?
PowerShell
Get-Service -Name wuauserv | Select-Object -Property Status
AAn error saying the service 'wuauserv' does not exist
BThe full details of the 'wuauserv' service including display name and service type
CA list of all services on the machine
DA table showing the Status property with values like 'Running' or 'Stopped'
Attempts:
2 left
💡 Hint
Think about what Select-Object does when you specify a property.
💻 Command Output
intermediate
2:00remaining
What happens when you run this command on a stopped service?
You run the following command on a service named 'Spooler' which is currently stopped. What will be the output?
PowerShell
Start-Service -Name Spooler; Get-Service -Name Spooler | Select-Object -Property Status
AIt outputs nothing because Get-Service fails after Start-Service
BIt throws an error because the service is stopped
CIt starts the Spooler service and outputs 'Running' as the Status
DIt outputs 'Stopped' because Start-Service does not change the status
Attempts:
2 left
💡 Hint
Start-Service changes the service state if possible.
📝 Syntax
advanced
2:00remaining
Which command correctly stops a service and waits for it to stop?
You want to stop the service named 'bits' and ensure it is fully stopped before continuing. Which command is correct?
AStop-Service -Name bits -Force -PassThru | Wait-Service -Status Stopped
BStop-Service -Name bits; Get-Service -Name bits | Where-Object { $_.Status -eq 'Stopped' }
CStop-Service -Name bits -Force; Start-Sleep -Seconds 5
DStop-Service bits -Wait
Attempts:
2 left
💡 Hint
Look for a way to wait for the service status after stopping it.
🔧 Debug
advanced
2:00remaining
Why does this script fail to start the service?
This script is supposed to start the 'w32time' service but fails with an error. What is the cause?
PowerShell
if ((Get-Service -Name w32time).Status -eq 'Running') {
  Write-Output 'Service already running'
} else {
  Start-Service -Name w32time
  Write-Output 'Service started'
}
AThe script fails because it does not have administrator privileges to start the service
BThe service name 'w32time' is incorrect and causes an error
CThe script syntax is invalid due to missing braces
DGet-Service does not return a Status property
Attempts:
2 left
💡 Hint
Starting services usually requires special permissions.
🚀 Application
expert
3:00remaining
How to create a script that restarts a service only if it is running?
You want a PowerShell script that restarts the 'Spooler' service only if it is currently running. Which script correctly does this?
AGet-Service -Name Spooler | Where-Object { $_.Status -eq 'Running' } | Restart-Service
Bif ((Get-Service -Name Spooler).Status -eq 'Running') { Restart-Service -Name Spooler } else { Write-Output 'Service not running' }
CStop-Service -Name Spooler; Start-Service -Name Spooler
DRestart-Service -Name Spooler -Force
Attempts:
2 left
💡 Hint
Check the service status before restarting it.