Last active
April 6, 2018 09:29
-
-
Save JohnLBevan/319c99c36a2753b3e95171f5d6daf99f to your computer and use it in GitHub Desktop.
Delete a Windows service (works fine with service names containing spaces too; uses the service's short name; i.e. Service Name rather than Display Name ). See https://stackoverflow.com/a/76127/361842 for more info.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Remove-Service { | |
| [CmdletBinding()] | |
| Param ( | |
| [Parameter()] | |
| [string]$Name | |
| ) | |
| Process { | |
| #could be improved by implementing everything the full suite of parameters that Start/Stop-Service have; for now just fulfils the most basic requirement | |
| Stop-Service -Name $Name -Force -ErrorAction SilentlyContinue | |
| sc.exe delete $Name | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can also be handled using WMI; I may change it in a later implentation to allow this to handle more advanced scenarios.
There's also a much better implementation coming soon to a PowerShell near you: PowerShell/PowerShell#4858