Solved

OR Statement in WMI Filter

Posted on 2013-01-30
3
1,081 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article runs through the process of deploying a single EXE application selectively to a group of user.
In-place Upgrading Dirsync to Azure AD Connect
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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