This guide will illustrate the usage of PowerShell’s “Restart-Service” cmdlet.
How to Use the Restart-Service (Microsoft.PowerShell.Management) Cmdlet in PowerShell?
First, write the stated cmdlet to utilize the “Restart-Service” cmdlet. Next, add the parameter “-Name” and provide it a service name to restart.
Let’s overview below-given illustrations to learn the usage of the stated cmdlet practically!
Example 1: Use the “Restart-Service” Cmdlet to Restart a Service
First, use the “Restart-Service” cmdlet. Then, write the “-Name” parameter and specify the service that you need to restart:
Example 2: Use the “Restart-Service” Cmdlet to Start All Stopped Device Services
Execute the below-mentioned command to start all the stop device services:
Following the above command:
- First, use the “Get-Service” cmdlet.
- Next, add the parameter “-Name” and provide it with the initial letters of service.
- Then, pipe it to the “Where-Object” cmdlet and specify the stated condition to get the stopped services.
- Lastly, pipe it to the “Restart-Service” cmdlet:
Example 3: Use the “Restart-Service” Cmdlet to Start Services Using the Display Name Parameter Excluding One Service
Initially, use the “Restart-Service” cmdlet. Then, type the “-DisplayName” parameter and specify the service starting letters enclosed with the wildcard “*” character. Lastly, write the “-Exclude” parameter and assign the stated service name:
That’s it! You have successfully learned the usage of the “Restart-Service” cmdlet.
Conclusion
The “Restart-Service” cmdlet is used to restart services in PowerShell. To do so, first, it sends a message to stop a specified service and then sends another message to start the service to the “Windows Controller Service”. This guide explained the “Restart-Service” cmdlet with the help of examples.