How do you wrap a variable into a search query and have the variable be a wildcard?
I've tried a number of things, but nothing is working.
Couple of issues here.
Number 1 don't use read-host for input. Create a function and make the computer and filter parameters
More importantly you're mixing wildcards
Your filter shouldn't be in quotes so looks like this
Where-Object name -like "*$searchterm*"
With WMI you can filter at the same time as getting the data – much faster so your code should look like this
$computername = $env:COMPUTERNAME
Use the -Argumentlist parameter on Invoke-command to pass the filter to Get-WmiObject.
You use the computrename parameter on Get-WmiObject or better still Get-CimInstance which would simplify the code
Get-WmiObject -Class Win32_Product -ComputerName $computername -Filter "Name LIKE '%$filter%'" | Select IdentifyingNumber, Name, LocalPackage
Get-CimInstance -ClassName Win32_Product -ComputerName $computername -Filter "Name LIKE '%$filter%'" | Select IdentifyingNumber, Name, LocalPackage
You must be logged in to reply to this topic.