Managing services lets you control programs running in the background on your computer. You can check if a service is running, start it, or stop it easily.
0
0
Service management (Get/Start/Stop-Service) in PowerShell
Introduction
You want to check if a printer service is running before printing.
You need to start a database service before using an application.
You want to stop a service that is causing problems.
You want to automate starting or stopping services during system setup.
Syntax
PowerShell
Get-Service [-Name] <string> Start-Service [-Name] <string> Stop-Service [-Name] <string>
Get-Service shows the status of a service.
Start-Service turns on a stopped service.
Stop-Service turns off a running service.
Examples
Check the status of the Windows Update service.
PowerShell
Get-Service -Name "wuauserv"Start the Print Spooler service to enable printing.
PowerShell
Start-Service -Name "Spooler"Stop the Print Spooler service to pause printing.
PowerShell
Stop-Service -Name "Spooler"Sample Program
This script checks if the Print Spooler service is running. If it is stopped, it starts it. If it is running, it stops it. Then it shows the final status.
PowerShell
Write-Host "Checking Print Spooler service status..." $service = Get-Service -Name "Spooler" Write-Host "Status: $($service.Status)" if ($service.Status -eq 'Stopped') { Write-Host "Starting Print Spooler service..." Start-Service -Name "Spooler" Write-Host "Service started." } else { Write-Host "Stopping Print Spooler service..." Stop-Service -Name "Spooler" Write-Host "Service stopped." } $service = Get-Service -Name "Spooler" Write-Host "Final Status: $($service.Status)"
OutputSuccess
Important Notes
You need to run PowerShell as Administrator to start or stop some services.
Service names are not case sensitive but must be exact.
Use Get-Service without parameters to list all services.
Summary
Use Get-Service to see if a service is running or stopped.
Use Start-Service to turn on a stopped service.
Use Stop-Service to turn off a running service.