Skip to content

About

My personal collection of SQL queries for Configuration Manager (SCCM / MECM)

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

SCCM SQL Query Collection

My personal collection of SQL queries for Configuration Manager (SCCM / MECM) site databases.

Highlights

  • 181 queries, one page each: a short description, formatted T-SQL, an anonymized sample output when one was available, and the source.
  • Client side: agent health, hardware and software inventory, BitLocker / TPM, software updates, task sequences, co-management.
  • Hierarchy side: boundaries and boundary groups, collections and their evaluation times, client settings, distribution points, site systems.
  • Content distribution, plus generic SQL Server maintenance queries for the site database (fragmentation, waits, expensive queries, backups, locks).
  • Organization-specific data removed and replaced by explicit placeholders such as <SITE_CODE> or <COLLECTION_ID>.

Overview

These queries come from the notes I kept while administering Configuration Manager: some written from scratch, some adapted from blogs, forums and Microsoft documentation, all used to answer recurring questions without rebuilding the same query every time. Each one now has its own page, filed in the same categories as the original notes, and every page credits its source.

Category Description Queries
01 Clients Queries returning information about client devices. 94
    ↳ Agent Management ConfigMgr client information: health and activity, certificates, co-management, duplicate records. 14
    ↳ Bitlocker BitLocker encryption status and TPM information. 5
    ↳ General Info Basic information about clients: name, user, MAC and IP addresses, domain, model, AD site, activation. 15
    ↳ Hardware Specific hardware information: laptops, disks, CPU, video cards, chassis, Autopilot hash, Windows 11 readiness. 12
    ↳ Software Installed software, Microsoft Office and 365 Apps, executables, deployments and application usage. 26
    ↳ Task Sequence Task sequence (OSD) executions, errors, runtimes and referenced driver packages. 5
    ↳ Updates Software update compliance, scan status, pending reboots, uptime and power plans. 14
    ↳ User User accounts: AD group membership and console usage. 2
02 Hierarchy Queries about the Configuration Manager hierarchy and its infrastructure. 44
    ↳ Boundaries And Boundary Groups Boundaries, boundary groups, fallback relationships and client assignment. 14
    ↳ Client Policies Client settings and the collections they are deployed to. 2
    ↳ Collections Collections, their query rules, dependencies and evaluation performance. 10
    ↳ Distribution Points Distribution point configuration, disk space, distribution jobs and orphaned references. 8
    ↳ Site Site systems and roles, management points, servicing updates and maintenance tasks. 10
03 Content Management Applications, packages, task sequence references and content distribution status. 21
04 DB Maintenance Generic SQL Server queries to maintain and troubleshoot the site database: performance, fragmentation, waits, backups, locks. 19
05 MBAM Queries against the Microsoft BitLocker Administration and Monitoring (MBAM) databases. 2
06 VAMT Queries against the Volume Activation Management Tool (VAMT) database. It usually runs on SQL Server Express and often cannot be queried remotely. 1

The full list is in the Index.

What it looks like

Every query page follows the same layout. For example, Client Health Statistics:

SELECT
    v_CH_ClientSummary.ClientstateDescription AS [ClientState],
    ROUND(100.0 * COUNT(*) / x.tot, 1) AS 'Percent',
    COUNT(v_CH_ClientSummary.ResourceID) AS [NumberofClients]
FROM
    v_CH_ClientSummary,
    (
        SELECT
            COUNT(*) AS tot
        FROM
            v_CH_ClientSummary
    ) x
GROUP BY
    v_CH_ClientSummary.ClientstateDescription,
    x.tot
ORDER BY
    [NumberofClients] DESC
ClientState Percent NumberofClients
Active/Pass 94.1 13762
Inactive/Pass 5.1 743
Active/Unknown 0.8 124

Illustrative values.

Usage

  1. Open the Index or a category README and pick a query.
  2. Copy it into SQL Server Management Studio (or any T-SQL client) connected to your site database (CM_<SITE_CODE>).
  3. Replace the placeholders (<SITE_CODE>, <COLLECTION_ID>, <HOSTNAME>…) with your own values; they are listed in Redaction conventions.

Requirements: read access to the site database (db_datareader, or the reporting RBAC functions) is enough for the reporting views (v_*). A few queries read internal tables, target the MBAM or VAMT databases or SQL Server DMVs, or need optional inventory classes; their pages say so under Notes.

Before you run a query:

  • Test it first. Most queries are read-only, but some are expensive on large databases: prefer off-peak hours or a reporting replica.
  • A few scripts modify the database. They carry a large warning at the top of their page. Direct changes to the Configuration Manager database are not supported by Microsoft.
  • Some queries were written for ConfigMgr 2007 / 2012 and may need adjustments on current branch.

Documentation

Feedback and Contributing

Bug reports, questions, corrections and missing credits are welcome as issues. Support and response time are limited, since this is maintained on a best-effort basis alongside everything else. If you are the author of a query that is not credited correctly, open an issue and I will fix the attribution or remove the query. See Contributing for the page layout and the SQL formatting standard.

License

MIT. See LICENSE. The MIT license covers only my own queries and the documentation: third-party queries remain the property of their authors, under their own terms. See NOTICE and Credits & sources.

Authors

Maintained by MonsieurPec.

The queries are a mix of my own work and community contributions, collected over years of administering Configuration Manager in OneNote. I exported those notes from OneNote to Markdown with Obsidian and its Importer plugin. The exported notes were then converted (extraction, SQL formatting, anonymization, transcription of the sample outputs and the documentation) and reviewed by me. Despite attention to details this project might contain errors.

Credits & sources.

About

My personal collection of SQL queries for Configuration Manager (SCCM / MECM)

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors