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. 


WMITanDepPackag_8082653b-f8a8-4a71-82e9-a9812489a97d.png
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" 

Note:

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.

  • Use Installed Application, Registry, and/or File rules instead.

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.

  • Constrain the query to a specific file path if it must be used.

  • Use File Version or File Path applicability rules instead where possible.

  • Use Tanium Index in targeting questions instead of Deploy software package applicability rules to safely find endpoints based on variable file paths.

  • Pair below other rules, such as File Exists, to ensure this is only executed where necessary. See Pair WMI applicability checks.

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 LocalAccount=True in the WMI query filter.

  • Use this query to build a rule that looks for the standard local  Administrator account:account:select Name from win32_useraccount Where LocalAccount = true AND Name Like "Administrator"

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


WMITanDepPackag_f4d9e7c2-5137-4dd8-b0ff-87dca5f7d763.png

This is a bad example because this package enumerates all hotfixes on every endpoint every time a catalog scan occurs.  

Better Example


WMITanDepPackag_94b0bba7-1d41-44cc-a908-01d1e05fd77f.png
Note:

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. 


WMITanDepPackag_15fc2c6b-5a6c-4ee2-a464-e53ee6a79d85.png

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 

Reference

Querying with WQL