Samples SQL Server utilization over multiple intervals using four DMV queries per sample: CPU (via ring buffer XML), memory (dm_os_process_memory + dm_os_sys_memory), runnable/active threads (dm_os_workers), and plan cache stats (dm_exec_query_stats). Aggregates Min/Max/Avg and outputs TXT, CSV, and an inline dark-theme HTML report.
Execution Flow
Synopsis
Takes $SampleCount snapshots spaced $SampleIntervalSeconds apart. Each snapshot fires four Invoke-DbaQuery calls concurrently. CPU is read from the ring buffer XML (dm_os_ring_buffers) rather than the OS — this yields SQL Server's own CPU view. After all samples are collected, the function aggregates Current/Min/Max/Avg for each metric and generates three output files. The HTML report embeds inline dark-theme CSS.
Requires dbatools. Default of 6 samples × 10 s = roughly 60 s total runtime. The CSV export contains raw per-sample rows; the TXT and HTML contain the aggregated summary. Output path defaults to Get-sqmDefaultOutputPath.
Pause between samples (skipped after the last sample).
-OutputPath
String
Get-sqmDefaultOutputPath
Directory for TXT, CSV (raw samples), and HTML report.
-EnableException
Switch
false
Throw terminating exceptions.
Return Value (Aggregated)
Property
Description
SqlInstance
Sampled instance.
SampleCount / SampleIntervalSeconds
Sampling parameters used.
CPU_Current / CPU_Min / CPU_Max / CPU_Avg
SQL Server CPU utilization % from ring buffer.
SQLMemoryGB_Current/Min/Max/Avg
SQL Server physical memory committed in GB.
AvailableMemoryGB_Current/Min/Max/Avg
Available OS physical memory in GB.
RunnableThreads_Current/Min/Max/Avg
Threads in RUNNABLE state (CPU pressure indicator).
ActiveThreads_Current/Min/Max/Avg
Threads in SUSPENDED or RUNNING state.
TxtFile / CsvFile / HtmlFile
Written report file paths.
Examples
# 60-second sample, local instanceGet-sqmServerUtilization# Quick 3-sample snapshot with short intervalGet-sqmServerUtilization-SqlInstance"SQL01"-SampleCount 3 -SampleIntervalSeconds 5
# Show only aggregated CPU
(Get-sqmServerUtilization).CPU_Avg