Working with Queries in ConfigMgr with PowerShell

I accidentally blew up my dev lab and now I need to build a new one but luckily we have PowerShell :).

In this picture we have 8 Queries and I would like to create Device Collections based on these Queries. These Queries are built with Servicing Extension.


Here are some of the commands that we can use in Configuration Manager 2012 R2 CU4. These commands allows us easily export/import Queries from one system to another and much more.

Little bit later we have nice Device Collections in System folder


Using the PowerShell GridView output we can easily explore the Collection membership count



PS – My next Configuration Manager 2012 R2 Automation with PowerShell is in June @LabCenter


Happy Scripting

About the Author:

Kaido Järvemets
Configuration Manager MVP


  1. Trevor March 23, 2015 at 12:02 - Reply

    Line 75 of the script: ‘QueryExpression’ is misspelt

  2. Bradley Plohr October 7, 2015 at 18:13 - Reply

    Do you have a script that will export all queries to a CSV and which can then be used to import to a new site?

Leave A Comment