Version: 2
restore

Contents

Method

RunWmiQuery

ModuleNativeServices
LibraryCore
Action

Execure a WMI query.

Parameters

Namespace (string): The WMI namespace to use. From v3.1, this parameter is optional and defaults to "root\cimv2" .

Query (string): The query expression.

ResultsAsText (boolean; optional, default false): If set, return a single-column string output (called "Data") with a quasi-JSON representation of the whole row. This allows execution of WMI queries and interpretation (or at least display) of the results without having to know the schema type up-front.

Return values

If  ResultsAsText  is false then returns a table of the results returned by the query.

If  ResultsAsText  is true then returns a Data  (string): A JSON-like representation of the results table.

Example
 NativeServices.RunWmiQuery(Namespace:"root\\cimv2", Query:"SELECT Manufacturer, BIOSVersion, SMBIOSBIOSVersion FROM Win32_BIOS");
 NativeServices.RunWmiQuery(Namespace:"root\\cimv2", Query:"SELECT Manufacturer, BIOSVersion, SMBIOSBIOSVersion FROM Win32_BIOS", ResultsAsText:true);
Platforms
  • Windows
Notes

Where possible, you should avoid using "SELECT * FROM..." in your WMI query, and instead prefer to SELECT specific columns.

This more efficient as the Agent will need to process less data, and is also less likely to cause compatibility problems in the future if the structure of the corresponding WMI class changes.