1

I have to do some powershell script modifications which I cannot test properly on my dev machine.

Thats why I would like to know, if I can use an OR-Operator in my Get-WmiObject -filter operation?

Currently we use

(Get-WmiObject -Class Win32_Product -Filter "Name like 'ApplicationName1 Client%'" ...).Uninstall()

But lately we renamed the name of the application from ApplicationName1 to NewName. Thats why I would like to add another condition like this:

(Get-WmiObject -Class Win32_Product -Filter "Name like 'ApplicationName1 Client%' OR Name like 'NewName Client%'" ...).Uninstall()

My question would be:

Is this a valid syntax for the filter or would this throw an exception / give an error? If it gives an error, how would you do this?

4
  • 3
    Has the thought to just try it occured to you? Commented Apr 26, 2016 at 9:52
  • "I have to do some powershell script modifications which I cannot test properly on my dev machine." Commented Apr 26, 2016 at 10:22
  • 2
    Seriously? You write scripts based on the statements of others and run them in a production environment without testing? Your line runs on every windows machine that has a powershell, by removing the .Uninstall() statement you can test the output quite safely. And it takes less time than even writing a question here. Commented Apr 26, 2016 at 10:26
  • Well, ofcourse it would go into test lab first. But building a package for the test lab is taking a bit of time and I thought, it would be better to just make sure. Anyways, I already got my confirmation, thats all I wanted to have ;) Commented Apr 26, 2016 at 10:34

1 Answer 1

7

Yes this is valid syntax

for example

Get-WmiObject -Class win32_product -filter "Name Like 'citrix%' OR name like 'Microsoft%'"

Would give every product that starts with Citrix AND every product that starts with Microsoft

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.