Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1249
  • Last Modified:

OR Statement in WMI Filter

I currently have a WMI query that applies to all computers but a specific model.

Select * From Win32_ComputerSystem WHERE NOT Model LIKE "%Latitude D610%"

Open in new window


How can I change this for more than one model? For example, how can I exclude two or three other models in this same filter?
0
Joseph Moody
Asked:
Joseph Moody
  • 2
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
something like this?
Select * From Win32_ComputerSystem WHERE NOT Model LIKE "%Latitude D610%" AND NOT Model LIKE "%Latitude 2%"
AND NOT Model LIKE "%Latitude 3%"
AND NOT Model LIKE "%Latitude 4%"

Open in new window

0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Great!

I was doing OR and not AND. Thank you.
0
 
Meir RivkinFull stack Software EngineerCommented:
use ExecQuery to run dynamic sql query instead of concatenate hardcoded all the models:
dim query = "Select * From Win32_ComputerSystem WHERE"
modelsArray = Array("Latitude D610", "Latitude D2", "Latitude D3")
For Each model In modelsArray
  query = query & " AND NOT Model LIKE ""%" & model & "%""
Next

query = Replace(query ,"WHERE AND","WHERE")

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery(query)

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now