Test your Collection WQL queries using WBEMTEST and PowerShell

Test your Collection WQL queries using WBEMTEST and PowerShell

  • Comments 4
  • Likes


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.


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


Click Connect


In Namespace type in the following


replace XXX with your SiteCode

If your connecting remotely


then click Connect


Click the Query button


Enter your WQL query and click Apply


If you have a valid query you should see a result



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



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' }


Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • 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 Root\SMS\Site_LRB -Query $WQL}

  • @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.

  • Thanks, great post.

  • Gr8 Site thx