Using WMI in Tanium Deploy for Package Verification
Overview
Tanium Deploy offers several kinds of applicability verifications for Windows endpoints including WMI. Windows Management Instrumentation (WMI) is a component of the Windows operating system for getting and setting configuration and data from endpoints. WMI uses a language called WQL which allows you to make SQL-like queries against the WMI data on an endpoint.
Using WMI in Tanium Deploy allows you to extend your packages for additional use cases such as:
-
Detect if components, features, or hotfixes are installed
-
Detect hardware and driver information
-
Detect disk encryption status
This article explains how to use WMI applicability checks and best practices for using WMI queries within Tanium Deploy packages.
How to use WMI Applicability checks in a Tanium Deploy package
A Tanium Deploy package can use one or more WMI checks for installation requirements, update detection, or install verification. A WMI applicability check requires a valid namespace and WQL query. The WMI applicability check result depends on if you are expecting the query to return results or to return no results.
This basic example shows how to do a basic WMI query.
-
From a new or existing package, go to Install Verification, click +Row, click Select Attribute from the dropdown list, and choose WMI Query.
-
Next select the operator, either returns results or returns no results.
-
Next type in the namespace (typically, root\cimv2).
-
Finally enter your WMI WQL query and click Apply.
This simple WMI query ensures that the endpoint must be connected to AC power to be applicable (that is, not on battery power).
Best practices for using WMI Queries with Tanium Deploy packages
Avoid SELECT *
If you search the Internet for example WMI queries, you are bound to find many examples. However, many examples simply use the format of “SELECT * FROM XYZ”. This is inefficient at best and may cause performance problems on endpoints. There is no need to return all columns from a query if you only need one or two columns.
Bad Example
Select * FROM win32_pnpsigneddriver WHERE DeviceName = "Intel(R) Wireless-AC 9560 160MHz" AND DriverVersion = "22.150.1.1"
Better Example
Select DeviceName,DriverVersion FROM win32_pnpsigneddriver WHERE DeviceName = "Intel(R) Wireless-AC 9560 160MHz" AND DriverVersion = "22.150.1.1"
In the second query, only values that are needed are retrieved.
Avoid expensive WMI calls
Not all WMI classes are equally performant. While it is possible to safely get some data with WMI queries, it is usually much more performant to use a different rule rather than querying WMI. The table below covers dangerous WMI name spaces and the recommended alternatives.
|
WMI Class |
Description |
Recommendation |
|---|---|---|
|
win32_product |
Get product information about products installed by the Windows Installer. This has a very high performance impact on all endpoints. |
This is explicitly blocked in Deploy software packages. This namespace should never be used in almost any context, even outside of Tanium.
|
|
win32_quickfixengineering |
Determine what Microsoft Updates installed by the Windows Update Agent are currently installed. This namespace is safe to use in a limited capacity on newer operating systems. It can have a high performance impact on older versions of Windows, especially those with a long servicing life such as Windows 10 LTSC editions. |
This should be avoided where possible and limited in scope. Use registry value data checks for Component-Based Servicing or file version checks for files modified by an update instead where possible. See Example using CBS Registry.
|
|
cim_datafile |
Find file information such as whether a file exists, its extension, or its version. Using this namespace causes WMI to enumerate all files that fall within the constraints of the query, which can be extremely resource-intensive. |
This namespace should not be used unless absolutely necessary.
|
|
win32_useraccount |
Used for identifying user accounts on an endpoint. This will generate calls to Active Directory when used for domain accounts, causing network traffic and CPU utilization on domain controllers. |
Never use this namespace in Tanium without including
|
Pair WMI applicability checks
If you do have to query WMI for applicability information, then pair your WMI applicability check with other checks that ensure the query is only run when necessary, on the endpoints that absolutely need it.
Bad Example
This is a bad example because this package enumerates all hotfixes on every endpoint every time a catalog scan occurs.
Better Example
In this example, the WMI Query only runs if all the above checks pass. This reduces the number of times endpoints needed to enumerate hotfixes via WMI.
This example is using a CBS registry check to determine the installation state of a hotfix or patch without enumerating WMI at all.
Do not get bit by <> (Less than and greater than operators)
WMI queries do allow less than and greater than operators, however all comparisons are treated as text. This can come back to bite you if you try to do a version string comparison. Example: 79.0.3945.88 is treated as greater than 79.0.3945.117 because it is doing a string comparison.
Other useful WMI Queries
|
Query Name |
Syntax |
|---|---|
|
Match Model Information |
SELECT Model FROM Win32_ComputerSystem WHERE Model LIKE "Latitude 7400" |
|
Identify Driver Versions |
SELECT DeviceName,DriverVersion FROM win32_pnpsigneddriver WHERE DeviceName = "Intel(R) Wireless-AC 9560 160MHz" AND DriverVersion = "22.150.1.1" |
|
Find Running Process |
SELECT name FROM win32_process WHERE name = 'setuphost.exe' |
|
Verify Windows Features |
SELECT name FROM Win32_OptionalFeature WHERE name='IIS-ManagementConsole' |
|
Check Service Exists |
SELECT name FROM Win32_Service WHERE name='W3svc' |
Use Microsoft PowerShell to validate and measure WMI WQL queries
You can use PowerShell to validate WMI WQL queries as well as measure how long it takes to return results.
From a PowerShell command prompt, type the following syntax:
PS > (Measure-Command {Get-CimInstance -namespace 'root\cimv2' -Query 'SELECT HotFixId FROM win32_quickfixengineering'}).Milliseconds
229
Use the Get-WmiObject cmdlet for legacy operating systems
PS > (Measure-Command {Get-WmiObject -namespace 'root\cimv2' -Query 'SELECT HotFixId FROM win32_quickfixengineering'}).Milliseconds
326