Solved

OR Statement in WMI Filter

Posted on 2013-01-30
3
1,006 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
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
Comment Utility
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 21

Author Closing Comment

by:Joseph Moody
Comment Utility
Great!

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

Expert Comment

by:sedgwick
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Weird DFS behavior... 5 44
Lockdown of laptops 10 37
lync 2013 7 30
get-aduser and get-adcomputer lastLogon and LastLogonDate 3 24
Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
Synchronize a new Active Directory domain with an existing Office 365 tenant
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…
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 to another domain controller. Log onto the new domain controller with a user account t…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now