<h2>Define a WMI query</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2025" /><meta name="DC.rights.owner" content="(C) Copyright 2025" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="task" /><meta name="DC.title" content="Define a WMI query" /><meta name="abstract" content="As part of creating or modifying a discovery pattern, you can use the WMI query operation to execute a query on a remote Windows system either explicitly or automatically. Successful values are logged in a specified target table." /><meta name="description" content="As part of creating or modifying a discovery pattern, you can use the WMI query operation to execute a query on a remote Windows system either explicitly or automatically. Successful values are logged in a specified target table." /><meta name="DC.subject" content="WMI query operation, Pattern Designer, WMI query" /><meta name="keywords" content="WMI query operation, Pattern Designer, WMI query" /><meta name="DC.relation" scheme="URI" content="../../../product/service-mapping/task/t_CreatePatternPatDef.html" /><meta name="DC.relation" scheme="URI" content="../../../product/it-operations-management/reference/r_ITOMApplications.html" /><meta name="DC.relation" scheme="URI" content="../../../product/it-operations-management/reference/itom-visibility-landing-page.html" /><meta name="DC.relation" scheme="URI" content="../../../product/service-mapping/concept/c_MappingPatternsCustomization.html" /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-08-03" /><meta name="DC.date.modified" content="2023-08-03" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="t_WMIQueryPatDef" /><link rel="stylesheet" type="text/css" href="../../../CSS/commonltr.css" /><title>Define a WMI query</title></head><body id="t_WMIQueryPatDef"> <div class="breadcrumb"><a class="link" href="../../../product/it-operations-management/reference/r_ITOMApplications.html" title="Get better visibility into your infrastructure and services, prevent service outages, and expand your organization's operational agility with ServiceNow IT Operations Management.">IT Operations Management</a> > <a class="link" href="../../../product/it-operations-management/reference/itom-visibility-landing-page.html" title="The ServiceNow ITOM Visibility product consists of ServiceNow Discovery, ServiceNow Service Mapping, Certificate Inventory and Management, Service Graph Connectors, CMDB 360, and Firewall Audits and Reporting. Discovery and Service Mapping give you a unified, connected view of your entire IT network and the services that it supports.">ITOM Visibility</a> > <a class="link" href="../../../product/service-mapping/concept/c_MappingPatternsCustomization.html" title="Service Mapping and Discovery use patterns in their discovery process that cover most industry standard network devices and applications. You can customize these patterns and create new ones.">Discovery patterns used by ITOM Visibility</a> > </div> <h1 class="title topictitle1" id="ariaid-title1">Define a WMI query</h1> <div class="body taskbody"><p class="shortdesc"><span class="ph">As part of creating or modifying a discovery pattern,</span> you can use the <span class="ph uicontrol">WMI query</span> operation to execute a query on a remote Windows system either explicitly or automatically. Successful values are logged in a specified target table.</p> <div class="section prereq p"> <p class="p">Role required: pd_admin</p> <p class="p">Navigate to the relevant pattern step:</p> <ol class="ol" id="t_WMIQueryPatDef__ol_zzm_qcv_fy"><li class="li" id="t_WMIQueryPatDef__id_NavigateRelevantSectionPatDef">On the pattern form, select the relevant identification section for <span class="ph">Discovery</span>.<p class="p">Alternatively, select the relevant identification or connection section for <span class="ph">Service Mapping</span>.</p> </li><li class="li">Select the relevant pattern step or click <img class="image" id="t_WMIQueryPatDef__image_ury_rr5_fy" src="../../it-operations-management/reuse/../../service-mapping/image/PatDefAddStepAbove.png" alt="Add a step button" /> to add a step.</li></ol> <p class="p">Basic knowledge of programming is desirable.</p> </div> <div class="section context"> <p class="p">This operation is relevant only for Windows.</p> </div> <ol class="ol steps"><li class="li step stepexpand"> <span class="ph cmd">Select <span class="ph uicontrol">WMI Query</span> from the <span class="ph uicontrol">Operation</span> list.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Define the namespace path in the <span class="ph uicontrol">Namespace</span> field.</span> </li><li class="li step stepexpand"> <span class="ph cmd">If in the debug mode:</span> <ol type="a" class="ol substeps" id="t_WMIQueryPatDef__substeps_ecx_3zd_j5"><li class="li substep substepexpand"> <span class="ph cmd">Click <span class="ph uicontrol">Statement Accelerator</span> to populate the table and field values automatically.</span> </li><li class="li substep substepexpand"> <span class="ph cmd">Select a table from the <span class="ph uicontrol">Table name</span> pane.</span> <div class="itemgroup info">The field values are displayed in the <span class="ph uicontrol">Fields</span> pane.</div> </li><li class="li substep substepexpand"> <span class="ph cmd">Define parameters and operators for the condition in the <span class="ph uicontrol">Add Condition Clause</span>.</span> <div class="itemgroup info">The actual query text is displayed in the <span class="ph uicontrol">Get Full Statement</span>.</div> </li></ol> </li><li class="li step stepexpand"> <span class="ph cmd">If not in the debug mode, enter the WMI query string in the <span class="ph uicontrol">Get Full Statement</span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Enter the variable for the table in which the retrieved data is saved in the <span class="ph uicontrol">Add Target Table</span> field.</span> <div class="itemgroup info">You can enter a value from the specific field in a table as described in <a class="xref" href="../reference/r_UsefulShortcutsPatDef.html" title="There are several ways to enter values in Pattern Designer. You can use the following types of values in patterns: strings, variables, concatenated variables, and eval() functions. Do not use GlideRecords in patterns.">Enter values and variables in patterns</a>.</div> </li><li class="li step stepexpand"> <span class="ph cmd">Select <span class="ph uicontrol">Use Cache</span> to save the operation results in cache on the <span class="ph">MID Server</span>.</span> <div class="itemgroup info">Use cache to optimize discovery and avoid creating unnecessary load on central shared components, such as load balancers. The base system keeps operation results in cache for an hour. </div> </li><li class="li step stepexpand"> <span class="ph cmd">Select <span class="ph uicontrol">Terminate</span> to stop discovery if no results are found.</span> </li><li class="li step stepexpand"> <span class="ph cmd">If in Debug mode, test the step by clicking <span class="ph uicontrol">Test</span> and checking that the operation brings the result you expected.</span> </li></ol> <div class="example" id="t_WMIQueryPatDef__example_rws_vpd_5bc"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="t_WMIQueryPatDef__table_b4m_bqd_5bc" class="table" frame="border" border="1" rules="all"><colgroup><col style="width:50%" /><col style="width:50%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d449174e240">This operation is used in</th><th class="entry cellrowborder" style="vertical-align:top;" id="d449174e243">This item</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e240 ">Hierarchy</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e243 ">Applications > Directory Services</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e240 ">CI Type</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e243 ">IIFP [cmdb_ci_directory_iifp]</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e240 ">Pattern</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e243 ">IIFP On Windows Pattern</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e240 ">Section</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e243 ">AD Home Forest connectivity stage-wmi</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e240 ">Step number and name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d449174e243 ">1. Get all agents details via WMI step</td></tr></tbody></table> </div> <p class="p">This step uses the WMI Query operation to extract data on agents from the MicrosoftIdentityIntegrationAgent namespace and save this data in the variable table named $ManagementAgents.</p> <div class="fig fignone" id="t_WMIQueryPatDef__fig_kn5_dnm_qy"><span class="figcap"><span class="fig--title-label">Figure 1. </span>WMI Query operation form</span> <br /><img class="image" id="t_WMIQueryPatDef__image_glh_ynm_qy" src="../image/PatDefWMIQueryExample.png" alt="WMI Query usage" /><br /> </div> </div> <div class="section postreq" id="t_WMIQueryPatDef__postreq_eft_5pw_yz"><ul class="ul" id="t_WMIQueryPatDef__ul_ld4_wjw_yz"><li class="li">Continue editing the pattern by <a class="xref" href="t_DefineDiscoveryStepsPatDef.html" title="For each Identification Section and Connection Section entry that you added to the discovery pattern, define discovery steps. These steps are the basis for discovery.">adding a new step and defining its operation</a> or</li><li class="li"><a class="xref" href="t_FinalizePatternPatDef.html" title="After you finish defining your pattern, make it ready for use by Service Mapping and Discovery.">Finalize the pattern</a>.</li></ul> <div class="sectiondiv">cmdb-key-value</div><span class="ph" id="t_WMIQueryPatDef__discovery-cloud-tag"><span class="ph">Discovery</span> also collects cloud tags that are specific to each virtual machine (VM) and saves them to the Key Value [cmdb_key_value] table.</span></div> </div> <div class="related-links"> <div class="familylinks"> <div class="parentlink"><strong>Parent Topic:</strong> <a class="link" href="../../../product/service-mapping/task/t_CreatePatternPatDef.html" title="Create or modify a discovery pattern and define its basic attributes.">Create or customize patterns</a></div> </div> </div></body></html></div>