Question

I am trying to get few items from registry by using where-object, I can only have one item filtered but multiple items...is there anything wrong with my script?

This code works fine for only one item

Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ |  
ForEach-Object {Get-ItemProperty $_.pspath} |
Where-Object {
$_.Displayname -like 'adobe air'
} |
Select-Object DisplayName,DisplayVersion |
Sort-Object DisplayName |
Out-GridView

But if i set it to filter multiple items, it runs, ends, without any result... any idea why?

Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ |  
ForEach-Object {Get-ItemProperty $_.pspath} |
Where-Object {
$_.Displayname -like 'adobe air' -and
$_.Displayname -like 'Java*' -and
$_.Displayname -like 'TeamViewer*'
} |
Select-Object DisplayName,DisplayVersion |
Sort-Object DisplayName |
Out-GridView

If I use

Where-Object {
$_.Displayname -like "Security*"
}

It only gives me 3 items matches Security, not all of them, Why?

Was it helpful?

Solution

The issue is the logic you put in. -and means both need to be true, use -or instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top