Created
January 4, 2017 19:58
-
-
Save dustinchilson/67783b9ce36217eefd7230d504adad7f to your computer and use it in GitHub Desktop.
Delete windows services with a string in the name
This file contains 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
foreach ($service in get-wmiobject win32_service | | |
where { $_.name -like "*TestString*"} ) { | |
if ($service.ProcessId -ne 0) { | |
Stop-Process $service.ProcessId -Force | |
} | |
& "sc.exe" delete $service.Name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment