Solved

OR Statement in WMI Filter

Posted on 2013-01-30
3
1,186 Views
Last Modified: 2013-01-30
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
Comment
Question by:Joseph Moody
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38835333
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
 
LVL 22

Author Closing Comment

by:Joseph Moody
ID: 38835368
Great!

I was doing OR and not AND. Thank you.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38835371
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question