PowerShell Stop-Service Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed Set-Service and New-Service cmdlets in PowerShell.
https://cloudaffaire.com/powershell-set-service-and-new-service-cmdlets/
In this blog post, we will discuss Stop-Service cmdlet in PowerShell. You can use Stop-Service cmdlet to stop windows services. Stop-Service cmdlet stops a service by sending a stop message to the windows service controller. You can use parameters like ‘name’,’displayname’ or ‘inputobject’ to pass the service name to Stop-Service cmdlet. You need to have permission to manage windows service to use Stop-Service cmdlet.
Stop-Service Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 |
## Stop-Service ## [-Force] ## [-NoWait] ## [-InputObject] ## [-PassThru] ## [-Include ## [-Exclude ## [-WhatIf] ## [-Confirm] ## [ |
Stop-Service Cmdlet Argument List:
- –Confirm: Prompts you for confirmation before running the cmdlet.
- –DisplayName: Specifies the display names of the services to stop. Wildcard characters are permitted.
- –Exclude: Specifies services that this cmdlet omits. The value of this parameter qualifies the Name parameter.
- –Force: Forces the cmdlet to stop a service even if that service has dependent services.
- –Include: Specifies services that this cmdlet stops. The value of this parameter qualifies the Name parameter.
- –InputObject: Specifies ServiceController objects that represent the services to stop. Enter a variable that contains the objects, or type a command or expression that gets the objects.
- –Name: Specifies the service names of the services to stop. Wildcard characters are permitted.
- –NoWait: Indicates that this cmdlet uses the no wait option.
- –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 Stop-Service Cmdlet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
######################################## ## PowerShell | Cmdlet | Stop-Service ## ######################################## ## PowerShell Latest Version (5) ## open PowerShell terminal as admin ## stop a windows service in PowerShell Stop-Service -Name "WerSvc" Get-Service -Name "WerSvc" ## stop a windows service that has dependent services Stop-Service -Name "EventLog" -Force Get-Service -Name "EventLog" ## stop a windows service without any wait in PowerShell Stop-Service -Name "Wecsvc" -NoWait Get-Service -Name "Wecsvc" ## stop a windows service by display name in PowerShell Stop-Service -DisplayName "Windows Defender Firewall" -Force Get-Service -DisplayName "Windows Defender Firewall" ## get all the stopped services in PowerShell Get-Service | Where-Object {$_.Status -eq "Stopped"} ## start all the services that were stopped in this demo Start-Service -Name "WerSvc" Start-Service -Name "Wecsvc" Start-Service -Name "EventLog" Start-Service -Name "mpssvc" |
Hope you have enjoyed this article. In the next blog post, we will discuss Start-Service CmdLet in PowerShell.
To Set more details on PowerShell, kindly follow below official documentation