Payton Flint's Tech Blog
Menu
  • Home
  • Blog
  • Categories
  • Resources
  • About
  • Contact
Menu

WQL Query Optimization & Collection Evaluation Run Time

Posted on September 15, 2022June 4, 2023 by paytonflint

As an engineer working with CM, it is likely you will find yourself running SQL reports to identify collections that may potentially be utilizing sub-optimal query-based membership rules. If these queries have been poorly written, it can waste valuable system resources. If you modify and optimize these queries, it would behoove you to validate (and quantify) the reduction in query run time. One way to do this would be to take a look at the collection evaluation full run time. If the run time has not reduced significantly, this query should be reevaluated.

The collection evaluation full run time is able to be viewed in CM, but for efficiency’s sake, I decided to write a script to generate a .CSV report based on a list of collection IDs. This script also handles the conversion from milliseconds to seconds for convenience. Please take note that this must be ran from your desired CM site, and that must be specified at <Insert Site Location>.

# Identify location of script
$ScriptPath = Split-Path ($MyInvocation.MyCommand.Path) -Parent

# Set collection ID list location
$AllCollIDs = Get-Content "$ScriptPath\IDList.txt"

# Install/check for ConfigurationManager module
try {
    Import-Module ConfigurationManager -ErrorAction 'Stop'
    Set-Location <Insert Site Location>
}
catch [System.IO.FileNotFoundException] {
    throw 'The ConfigurationManager module cannot be found.'
}

# Run through list of IDs
$Output = foreach ($ID in $AllCollIDs) {

    # Get duration from CollEval & convert to seconds
    $Length = [Math]::Round((Get-CMCollectionFullEvaluationStatus -ID $ID | Select-Object -ExpandProperty Length)/1000)

    # Create table
    [PSCustomObject]@{
        Name =   $ID
        Length = $Length
    }
}

# Revert to local
Set-Location $env:SystemDrive

# Write output to .CSV at parent directory
$Output | Export-Csv -Path "$ScriptPath\CollEvalRunTime_Output.csv" -NoTypeInformation

Leave a Reply Cancel reply

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

About The Author

Author's Portrait

In my journey as a technologist and 11 years of experience as an IT professional, I have found my niche as Director of Infrastructure Services; developing my skillsets in management, scripting, cloud infrastructure, identity management, and networking.

I have experience as a Systems Administrator and Engineer for large enterprises including the DoD, government agencies, and a nuclear-generation site.

I've been blessed to collaborate with engineers at esteemed Fortune 50 corporations, and one of Africa's largest, to ensure successful implementation of my work.

GitHub Button

Credentials

M365 Endpoint Administrator Associate
M365 Fundamentals
Microsoft AZ-900
CompTIA CSIS
CompTIA CIOS
CompTIA Security+
CompTIA Network+
CompTIA A+
  • April 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
© 2022 Payton Flint | The views and opinions expressed on this website belong solely to the author/owner and do not represent the perspectives of any individuals, institutions, or organizations, whether affiliated personally or professionally, unless explicitly stated otherwise. The content and products on this website are provided as-is with no warranties or guaranties, are for informational/demonstrative purposes only, do not constitute professional advice, and are not to be used maliciously. The author/owner is not responsible for any consequences arising from actions taken based on information provided on this website, nor from the use/misuse of products from this site. All trademarks are the property of their respective owners.