# Get-WmiObject filter question

**URL:** <https://forums.powershell.org/t/get-wmiobject-filter-question/10693>\
**Category:** PowerShell Help\
**Created:** [May 22, 2018, 11:19am UTC](https://forums.powershell.org/t/get-wmiobject-filter-question/10693 "2018-05-22T11:19:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![johndav](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@johndav](https://forums.powershell.org/u/johndav)\
**Post date:** [May 22, 2018, 11:19am UTC](https://forums.powershell.org/t/get-wmiobject-filter-question/10693/1 "2018-05-22T11:19:26Z")

</div>

I need to run a Get-WmiObject command that filters for 2 criteria.

I need to combine the following 2 filters…but for the life of me, I can’t figure out how to use the -And operator to get it to work.

Should I be using a -Filter or a Where statement?

```
Get-WmiObject -Namespace root\cimv2\sms -class SMS_InstalledSoftware -Filter "ARPDisplayName LIKE 'Box for Office'"
```

```
Get-WmiObject -Namespace root\cimv2\sms -class SMS_InstalledSoftware -Filter "ProductVersion LIKE '4.3.1217.0'"
```

Thanks very much.

---

<div class="post-metadata">

**Author:** ![bo1](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/bo1/32/33_2.png) [@bo1](https://forums.powershell.org/u/bo1)\
**Post date:** [May 22, 2018, 11:57am UTC](https://forums.powershell.org/t/get-wmiobject-filter-question/10693/2 "2018-05-22T11:57:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![johndav](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@johndav](https://forums.powershell.org/u/johndav)\
**Post date:** [May 22, 2018, 12:04pm UTC](https://forums.powershell.org/t/get-wmiobject-filter-question/10693/3 "2018-05-22T12:04:20Z")

</div>

Thanks. It looks like the following is going to work for me.

```
Get-WmiObject -Namespace root\cimv2\sms -class SMS_InstalledSoftware | Where {$_.ARPDisplayname -eq 'Box for Office' -and $_.ProductVersion -eq '4.3.1217.0'}
```

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [May 22, 2018, 4:39pm UTC](https://forums.powershell.org/t/get-wmiobject-filter-question/10693/4 "2018-05-22T16:39:03Z")

</div>

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](https://msdn.microsoft.com/en-us/library/aa394605(v=vs.85).aspx)

```
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
```

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [May 23, 2018, 8:10am UTC](https://forums.powershell.org/t/get-wmiobject-filter-question/10693/5 "2018-05-23T08:10:49Z")

</div>

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'"
```

---

<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:35pm UTC](https://forums.powershell.org/t/get-wmiobject-filter-question/10693/6 "2024-05-16T20:35:02Z")

</div>

Closed on May 16, 2024, 8:35pm UTC


