# Getting Software Title and Product ID from remote PC using WMI w/ variable in PS

**URL:** https://forums.powershell.org/t/getting-software-title-and-product-id-from-remote-pc-using-wmi-w-variable-in-ps/5203
**Category:** PowerShell Help
**Created:** [November 11, 2015, 4:53am UTC](https://forums.powershell.org/t/getting-software-title-and-product-id-from-remote-pc-using-wmi-w-variable-in-ps/5203 "2015-11-11T04:53:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![andrew-powell](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/andrew-powell/32/217_2.png) [@andrew-powell](https://forums.powershell.org/u/andrew-powell)
#### Post date: [November 11, 2015, 4:53am UTC](https://forums.powershell.org/t/getting-software-title-and-product-id-from-remote-pc-using-wmi-w-variable-in-ps/5203/1 "2015-11-11T04:53:02Z")

</div>

How do you wrap a variable into a search query and have the variable be a wildcard?  
$PCName = Read-Host -Prompt "Enter PC Name: "  
$searchterm = Read-Host -prompt "Enter search term: "  
Invoke-Command -Computername $PCName {Get-WmiObject -Class Win32\_Product | Where-Object “name -like ‘%$searchterm%’” | FT IdentifyingNumber, Name, LocalPackage}

I’ve tried a number of things, but nothing is working.

---

<div class="post-metadata">

### Author: ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)
#### Post date: [November 11, 2015, 6:21am UTC](https://forums.powershell.org/t/getting-software-title-and-product-id-from-remote-pc-using-wmi-w-variable-in-ps/5203/2 "2015-11-11T06:21:15Z")

</div>

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  
% is the wildcard when you’re using WQL or a WMI filter

- is the wildcard when you’re using strings in where-object

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  
$filter = ‘Live’  
$scriptblock = {  
param($filter)  
Get-WmiObject -Class Win32\_product -Filter “Name LIKE ‘%$filter%’” |  
Select IdentifyingNumber, Name, LocalPackage }  
Invoke-Command -ComputerName $computername -ScriptBlock $scriptblock -ArgumentList $filter

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

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:44pm UTC](https://forums.powershell.org/t/getting-software-title-and-product-id-from-remote-pc-using-wmi-w-variable-in-ps/5203/3 "2024-05-16T20:44:28Z")

</div>


