Partager via


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

Comments

  • Anonymous
    January 01, 2003
    @Frank Thanks for testing this out and providing feedback. I've tested it again and noticed the difference as well and updated the post with a measure of the actual Expression itself.
  • Anonymous
    January 01, 2003
    Thanks, great post.
  • Anonymous
    August 20, 2014
    I think the used Measure-Command is wrong. I does not show the time to run the actual WMI query, it only displays how long it takes to read the variable $WMI. To measure the actual query it should be something like: Measure-Command -Expression {$WMI = Get-WmiObject -Namespace RootSMSSite_LRB -Query $WQL}
  • Anonymous
    February 17, 2015
    Gr8 Site thx