PowerShell Restart-Service Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed Start-Service cmdlet in PowerShell.
https://cloudaffaire.com/powershell-start-service-cmdlet/
In this blog post, we will discuss Restart-Service cmdlet in PowerShell. You can use Restart-Service cmdlet to restart windows services. Restart-Service cmdlet first stops a service if it’s not already stopped by sending a stop message to the windows service controller. And then start the service by sending a start message to windows service controller. You can use parameters like ‘name’,’displayname’ or ‘inputobject’ to pass the service name to Restart-Service cmdlet. You need to have permission to manage windows service to use Restart-Service cmdlet.
Restart-Service Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 |
## Restart-Service ## [-Force] ## [-InputObject] ## [-PassThru] ## [-Include ## [-Exclude ## [-WhatIf] ## [-Confirm] ## [ |
Restart-Service Cmdlet Argument List:
- –Confirm: Prompts you for confirmation before running the cmdlet.
- –DisplayName: Specifies the display names of the services to restart. Wildcard characters are permitted.
- –Exclude: Specifies services that this cmdlet omits. The value of this parameter qualifies the Name parameter.
- –Force: Forces the command to run without asking for user confirmation.
- –Include: Specifies services that this cmdlet restarts. The value of this parameter qualifies the Name parameter.
- –InputObject: Specifies ServiceController objects representing the services to be restarted. Enter a variable that contains the objects, or type a command or expression that gets the objects.
- –Name: Specifies the service names for the service to be restarted.
- –PassThru: Returns an object that represents the service. By default, this cmdlet does not generate any output.
- –WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.
PowerShell Restart-Service Cmdlet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
########################################### ## PowerShell | Cmdlet | Restart-Service ## ########################################### ## PowerShell Latest Version (5) ## open PowerShell terminal as admin ## restart a windows service by name in PowerShell Restart-Service -Name "WerSvc" Get-Service -Name "WerSvc" ## restart a windows service by display name in PowerShell Restart-Service -DisplayName "Windows Error Reporting Service" Get-Service -DisplayName "Windows Error Reporting Service" ## restart a windows service that has dependent services Restart-Service -Name "EventLog" -Force Get-Service -Name "EventLog" |
Hope you have enjoyed this article. In the next blog post, we will discuss Suspend-Service CmdLet in PowerShell.
To Set more details on PowerShell, kindly follow below official documentation