← PowerShell course
5

Managing Services & Processes

25 min

Hunt down stopped services, preview restarts safely with -WhatIf, and silence memory-hungry processes — the real on-call toolkit.

By the end you can
  • Filter services by Status and StartType using Get-Service and Where-Object
  • Preview and execute service restarts with -WhatIf, Start-Service, Stop-Service, and Restart-Service
  • Identify top memory consumers with Get-Process and Sort-Object
  • Terminate unresponsive processes safely using Stop-Process -Force -Id
  • Automate bulk restarts with ForEach-Object across a filtered service list

Services & Processes: The On-Call Toolkit

It is 02:00. Monitoring wakes you: the nightly ETL job has failed again. Nine times out of ten the culprit is a Windows service that stopped quietly. This module is how you fix it — fast, safely, and without guessing.

Getting a Picture of Your Services

Get-Service returns every service on the local machine:

Get-Service

Each object has three properties you will lean on constantly:

PropertyExample values
Namewuauserv, Spooler, bits
StatusRunning, Stopped, Paused
StartTypeAutomatic, Manual, Disabled

Narrow to services that should be running — StartType Automatic AND currently Stopped:

Get-Service | Where-Object { $_.StartType -eq 'Automatic' -and $_.Status -eq 'Stopped' }

These are your suspects.

Changing Service State Safely

Before you touch anything, use -WhatIf. Every *-Service cmdlet supports it:

Restart-Service -Name 'Spooler' -WhatIf
# What if: Performing the operation "Restart-Service" on target "Print Spooler (Spooler)".

No change occurs — you just confirm the right target. When you are happy:

Restart-Service -Name 'Spooler'
Start-Service  -Name 'bits'
Stop-Service   -Name 'Spooler'

Finding Heavy Processes

Get-Process lists every running process. The WS (Working Set) property is RAM in bytes. Sort descending and take the top five:

Get-Process | Sort-Object WS -Descending | Select-Object -First 5

To kill an unresponsive process use -Id (never rely on name alone — multiple processes can share a name) and add -Force for stubborn ones:

Stop-Process -Id 4812 -Force

Bulk Restarts with ForEach-Object

Automate the restart of every stopped-but-should-be-running service in one pipeline:

Get-Service |
    Where-Object { $_.StartType -eq 'Automatic' -and $_.Status -eq 'Stopped' } |
    ForEach-Object { Restart-Service -Name $_.Name -Verbose }

When You Need Richer Data

Get-Service is fast but lean. Get-CimInstance Win32_Service returns extra fields such as PathName, ProcessId, and Description:

Get-CimInstance -ClassName Win32_Service -Filter "State = 'Stopped' AND StartMode = 'Auto'"