Retrieve All Queries in SCCM using SQL Query

Retrieve All Queries in SCCM using SQL Query

Last Updated

March 9, 2026

Posted In

In this post, I will demonstrate how you can retrieve all queries in SCCM using SQL query. The query basically lists all the queries created in Configuration Manager along with the query name, ID, and description.

In Microsoft Configuration Manager (SCCM), queries in the Monitoring workspace are used to retrieve information about the environment, create dynamic collections, and generate reports for system health, deployments, and inventory.

At my previous organization, I managed a big team of engineers who created multiple queries in Configuration Manager for work purposes. Some queries were imported, while others were created manually. Over the time, there were plenty of queries and some of them were actually redundant.

Install and Update Third Party Applications with Patch My PC
Install and Update Third Party Applications with Patch My PC

Retrieve All Queries in SCCM using SQL Query

If you find yourself needing to review and export multiple queries from your ConfigMgr setup for auditing purposes, here’s how you can accomplish that efficiently using a SQL query. Launch the SQL Server Management studio (SSMS) and connect to the database engine. Expand Databases and right-click SCCM database and select New Query. In the query window, paste and execute the below query.

Select
QueryKey 'Query ID', 
Name 'Query Name', 
Comments 'Query Comments', 
Architecture 'Query Object Type',
CollectionID 'Limit To Collection ID'
From Queries Order by 'Query Name'

The above query returns all the queries that are present in Configuration Manager and the output includes the columns such as Query ID, Name, Comments, Object Type, etc. You may sort the data using Query ID or Query Name.

Retrieve All Queries in SCCM using SQL Query
Retrieve All Queries in SCCM using SQL Query

Exporting All SCCM Queries

To export the data of all queries in SCCM to Excel or CSV File, press Ctrl + A and right-click on the data and select save results as. Choose a.csv or .txt file to save the details.

Export All Queries in SCCM to Excel or CSV File
Export All Queries in SCCM to Excel or CSV File

Also Read

Leave a Reply

Your email address will not be published. Required fields are marked *

Prajwal Desai

Prajwal Desai is a highly accomplished technology expert and an 11-time Dual Microsoft MVP (Most Valuable Professional), specializing in Microsoft Intune, SCCM, Windows 365, Enterprise Mobility, and Windows. As a renowned author, speaker, and community leader, he is widely recognized for sharing his in-depth expertise and insights through his blog, YouTube channel, conferences, webinars, and other platforms.