How to check whether a specific service exists using Powershell?
You can specify the service name using the -Name
attribute. By default if it doesn't see a matching service it will give an error. Using -ErrorAction SilentlyContinue
you can get an empty variable back.
$service = Get-Service -Name W32Time -ErrorAction SilentlyContinue
Once you have that you can just see if the length is greater than 0.
if ($service.Length -gt 0) {
# Do cool stuff
}