Execution Flow
Synopsis
A single DMV query against sys.dm_os_performance_counters returns the ~20 most important SQL Server health indicators. Buffer Cache Hit Ratio is computed from the ratio counter pair. Page Life Expectancy, blocking, deadlocks, memory pressure, and re-compilations are automatically flagged with localized interpretation strings via the _s helper. Results are returned as a structured object with a Summary and a Counters array.
Requires dbatools and VIEW SERVER STATE. Uses the
_s localization helper for all interpretation strings. Counters values are point-in-time snapshots, not rates — for /sec counters, two readings are needed to calculate the actual rate.Syntax
Get-sqmPerfCounters [-SqlInstance <String>] [-SqlCredential <PSCredential>] [-Category <String[]>] # e.g. @('Buffer','Memory','Locks') [-TopN <Int>] # 1-500, default 50 [-OutputPath <String>] [-EnableException]
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| -SqlInstance | String | $env:COMPUTERNAME | SQL Server instance to query. |
| -SqlCredential | PSCredential | — | Credential for the SQL connection. |
| -Category | String[] | all | Filter counters by ObjectName fragment. Example: @('Buffer','Locks'). |
| -TopN | Int | 50 | Maximum number of counter rows (1–500). |
| -OutputPath | String | — | If set: write CSV and HTML to this directory. |
| -EnableException | Switch | false | Throw terminating exceptions. |
Return Value
| Property | Description |
|---|---|
| Summary.BufferCacheHitRatioPct | Computed BHR percentage from ratio counter pair. |
| Summary.PageLifeExpectancy | PLE value in seconds. |
| Summary.UserConnections | Current user connection count. |
| Summary.Warnings | Number of counters with non-empty Interpretation. |
| Counters[] | Array of PSCustomObject: Category, CounterName, InstanceName, Value, Interpretation. |
Examples
# All counters, local instance Get-sqmPerfCounters # Filter to Buffer and Memory categories Get-sqmPerfCounters -SqlInstance "SQL01" -Category "Buffer","Memory" # Show only flagged counters (Get-sqmPerfCounters).Counters | Where-Object { $_.Interpretation -ne '' }