Test your Collection WQL queries using WBEMTEST and PowerShell

 

Hi All,

one of the most useful tips I've learnt on the job is to use WBEMTEST on your Primary Site Server to test your Collection WQL queries. This is useful for doing things like testing the time it takes to run that query. This is especially useful when you get collections that take a very long time to run potentially causing backlogs and delays in collections updating. Using these tools can help you quickly test the queries for timing outside of Configuration Manager.

WBEMTEST

Log onto your Site Server or from your tools machine you can connect remotely. Ill show you both methods.

Start up WBEMTEST from a command line

image

Click Connect

image

In Namespace type in the following

root\SMS\SITE_XXX

replace XXX with your SiteCode

If your connecting remotely

\\Computername\root\SMS\SITE_XXX

then click Connect

image

Click the Query button

image

Enter your WQL query and click Apply

image

If you have a valid query you should see a result

image

PowerShell

You could also run a similar query using PowerShell (Thanks to my fellow PFE’s Ryan Hall and Anthony Watherston for this.)

just replace the value in the $WQL variable quotes with your query and of course PRI with your SiteCode.

$WQL = 'select * from SMS_R_SYSTEM'

$WMI = Get-WmiObject -Namespace Root\SMS\Site_PRI -Query $WQL

$WMI

image

and if I want to measure that command for approximate timing

Measure-Command -Expression {Get-WmiObject -Namespace Root\SMS\Site_PRI -Query 'select * from SMS_R_SYSTEM' }

image