Using Suspend-Service in PowerShell
Welcome back to Wahmans Powershell blog! In today’s post, we are exploring the Suspend-Service cmdlet — a simple yet powerful tool in PowerShell that allows you to pause a running service on your system.
According to Microsoft, Suspend-Service “Suspends (pauses) one or more running services.” Be aware that not all services support pausing — some services can only be stopped or restarted.
Syntax
Suspense-Service [-Name] <String[]> [-Force] [-PassThru] [-WhatIf] [-Confirm] [CommonParameters]
Example Use Cases
1. Pausing a Simple Service (Beginner)
Let’s say you want to pause the Spooler service (Print Spooler). Here’s how to do it:
Suspend-Service -Name Spooler
Keep in mind that if the service doesn’t support pausing, an error will be thrown.
2. Check If the Service Is Running Before Pausing (Intermediate)
This next example adds a conditional check to see if the service is running before attempting to pause it:
$service = Get-Service -Name Spooler
if ($service.Status -eq 'Running') {
Suspend-Service -Name Spooler
Write-Host "Spooler service paused."
} else {
Write-Host "Spooler service is not running."
}
3. Pausing Multiple Services (Intermediate)
You can pause more than one service at once using an array:
$servicesToPause = @("Spooler", "wuauserv")
foreach ($svc in $servicesToPause) {
try {
Suspend-Service -Name $svc -ErrorAction Stop
Write-Host "Paused $svc"
} catch {
Write-Host "Could not pause $svc: $_"
}
}
This handles errors gracefully in case a service cannot be paused.
4. Schedule to Pause a Service during Maintenance Window (Advanced)
Here’s an example of using Suspend-Service as part of a scheduled maintenance script at specific times. This would often be set to run by Task Scheduler.
# MaintenancePause.ps1
$target = "Spooler"
$service = Get-Service -Name $target
if ($service.Status -eq 'Running') {
Suspend-Service -Name $target
Start-Sleep -Seconds 60 # Wait for 1 minute
Resume-Service -Name $target
Write-Output "$target has been paused and resumed."
} else {
Write-Output "$target was not running at scheduled time."
}
This can be useful during patch cycles or low-activity periods when you want to temporarily pause a service.
Conclusion
The Suspend-Service cmdlet is a handy tool within the PowerShell toolkit — when used appropriately. Just remember: not all services allow pausing. Always test and validate your scripts in a safe environment before introducing them into production.
Happy scripting, and I will see you in the next post!
Leave a Reply