PowerShell for Windows Admins

Oct 31 2011   2:03PM GMT

Multiple value query in WQL

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: