The -Filter paremeter for Get-WMIObject is looking for WQL syntax
Get-Help Get-WmiObject -Parameter Filter
-Filter
Specifies a Where clause to use as a filter. Uses the syntax of the WMI Query Language (WQL).
Important: Do not include the Where keyword in the value of the parameter. For example, the following commands return only the logical disks that have a DeviceID of 'c:'
and services that have the name 'WinRM' without using the Where keyword.
`Get-WmiObject Win32_LogicalDisk -filter "DeviceID = 'c:' "`
`Get-WmiObject win32_service -filter "name='WinRM'"`
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
Unless you enjoy WQL a Where-Object would be easier IMO.
You should always filter as far left as possible, so you should leverage the WMI filter. WQL does support LIKE, however, in your posted examples I didn’t see a wildcard character (but it could be the site). This article discusses WQL Operators: WQL Operators - Win32 apps | Microsoft Docs
PS C:\Users\Rob> Get-WMIObject -Class Win32_Service -filter "Name like 'box%'"
ExitCode : 0
Name : BoxSyncUpdateService
ProcessId : 0
StartMode : Manual
State : Stopped
Status : OK
PS C:\Users\Rob> Get-CimInstance -ClassName Win32_Service -Filter "Name like 'box%'"
ProcessId Name StartMode State Status ExitCode
--------- ---- --------- ----- ------ --------
0 BoxSyncUpdateService Manual Stopped OK 0
A -filter (with this command) is the same as the where clause in sql, and a -query is the same as sql. Just use ‘and’. You can use ‘=’ instead of ‘like’, since you aren’t using the ‘%’ wildcard. A -filter is faster than piping to where-object, if you’re dealing with a lot of instances. ‘=’ is faster than ‘like’ as well.
Get-WmiObject -Namespace root\cimv2\sms -class SMS_InstalledSoftware -Filter "
ARPDisplayName = 'Box for Office' and ProductVersion = '4.3.1217.0'"
A good example for a filter (have to double up the backslashes), since there’s a ton of directory instances (95,000 on my computer):
Get-WmiObject win32_directory -filter "name = 'c:\\' or name = 'c:\\users'"