2

I am trying to list some of software installed on a PC by using:

Get-WmiObject -Class Win32_Product |
Select-Object -Property name,version |
Where-Object {$_.name -like '*Java*'}

It works, but when I added more names in Where-Object it gave me no results neither an error.

Get-WmiObject -Class Win32_Product |
Select-Object -Property name,version |
Where-Object {$_.name -like '*Java*','*python*','*adobe*','*access*'}

Why does it only work with one name?

1
  • BTW, how about listing all 64 bit software? I dont think there is a 'Win64_Product' command Commented May 20, 2014 at 20:21

2 Answers 2

4

I don't think -like will take an array on the right hand side. Try a regex instead:

Where-Object {$_.name -match 'Java|python|adobe|access'}
Sign up to request clarification or add additional context in comments.

2 Comments

yes, looks like -like wont take array...Thanks, will accept answer after 7 mins
BTW, how about listing all 64 bit software? I dont think there is a 'Win64_Product' command
1

The -Like operator takes a string argument (not a string array), so whatever you give it will get cast as [string]. If you cast the arguments you've give it to string:

[string]('*Java*','*python*','*adobe*','*access*') 

you get:

*Java* *python* *adobe* *access*

and that's what you're trying to match against (and you don't have any file names that look like that).

The easiest way to do this is switch to the -match operator, and an alternating regex:

Where-Object { $_.name -match 'Java|python|adobe|access' }

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.