In this tutorial, we will describe the usage of the “Suspend-Service” cmdlet.
How to Use the Suspend-Service (Microsoft.PowerShell.Management) Cmdlet in PowerShell?
To suspend service in PowerShell, first, use the “Suspend-Service” cmdlet. Then, specify the service by using the “-Name” or the “-DisplayName” parameter.
To understand the usage of the “Suspend-Service” cmdlet, check out the provided examples.
Example 1: Use the “Suspend-Service” Cmdlet to Suspend a Specified Service
First, use the “Suspend-Service” cmdlet. Then, write the “-DisplayName” parameter and assign it a service that needs to suspend:
Use the below-stated command to check whether the service was suspended or not:
Example 2: Use the “Suspend-Service” Cmdlet to Check What Will Happen If you Suspend the Specified Service
To view the consequences after suspending the service, simply use the “-WhatIf” parameter:
Example 3: Use the “Suspend-Service” Cmdlet to Suspend all the Suspendable Services
Execute the below-mentioned command to suspend all the suspendable services:
According to the above code:
- First, use the “Get-Service” cmdlet and pipe it to the “Where-Object” cmdlet’s specified condition.
- Then, pipe the specified “Where-Object” condition to the “Suspend-Service” cmdlet.
- Lastly, use the “-Confirm” parameter to ask for user confirmation at the prompt:
Type “A” when the PowerShell console asks for confirmation.
Example 4: Use the “Suspend-Service” cmdlet to Get and Suspend the Specified Service
To retrieve and suspend a particular service, first, use the “Get-Service” along with the service name and then pipe it to the “Suspend-Service” cmdlet:
Run the given command to verify whether the service was suspended or not:
That’s it! We have compiled the usage of the “Suspend-Service” cmdlet.
Conclusion
PowerShell’s “Suspend-Service” cmdlet suspends/pauses running services. A service that needs to be suspended is specified to the “Suspend-Service” cmdlet using its name or display name. This tutorial demonstrated the practical usage of PowerShell’s “Suspend-Service” cmdlet with the help of various examples.