A simple query that demonstrates how to query for multiple values. We want to stop the running services that are running where the names a like BITS and WinRm
Get-WmiObject -Class Win32_Service -Filter "State=’Running’ AND Name LIKE ‘%BITS%’ OR Name LIKE ‘%WinRM%’" |
Invoke-WmiMethod -Name StopService
Define the service state and use AND to link to the names and then OR to say you want name A or name B. If it is easier to visualise use the syntax like this
Get-WmiObject -Class Win32_Service -Filter "State=’Running’ AND (Name LIKE ‘%BITS%’ OR Name LIKE ‘%WinRM%’)"
It does work!
To restart the services
Get-WmiObject -Class Win32_Service -Filter "State=’Stopped’ AND Name LIKE ‘%BITS%’ OR Name LIKE ‘%WinRM%’" |
Invoke-WmiMethod -Name StartService