Enterprise SQL Server Administration & AlwaysOn Automation Toolkit
A comprehensive PowerShell module for SQL Server 2016+ administration, with specialized support for AlwaysOn Availability Groups, performance reporting, and security auditing.
Latest Release: v1.9.80.0 | Functions: 163 | Documentation: Full Reference
New-sqmAgentCommandJob- generic SQL Agent job/step builder that wraps any sqmSQLTool function via a Clixml-serialized parameter splatExport-sqmDatabaseLogins/Import-sqmDatabaseLogins/Sync-sqmDatabaseLogins- database-level login export, import, and sync- AlwaysOn rejoin fixes: correct recovery model on rejoin, automatic backup lookup by database name
Get-sqmLoginSettings,Get-sqmAlwaysOnFailoverHistory,Get-sqmTlsStatus,Invoke-sqmInstanceInventoryand 33 other report functions now write automatic TXT/CSV/HTML output to their own subfolder by defaultGet-sqmSpnReportno longer flags AG partner-replica SPNs or duplicate listener SPN rows as errors
Get-sqmPlanInsights parses ShowPlan XML (.sqlplan/.xml) and reports cardinality-estimate mismatches, SARGability violations, parameter-sniffing risk, tempdb spills, and missing-index suggestions — with runtime-evidence-based severity scoring instead of relying on optimizer cost estimates:
# Find the most expensive statements in the plan cache and export their plans
$top = Get-sqmPlanCacheReport -SqlInstance "SQL01" -SortBy CPU -Top 5 -ExportPlans
# Offline analysis of a saved plan
Get-sqmPlanInsights -Path $top[0].PlanFile
# With live Query Store telemetry and a JSON bundle for the visualizer
Get-sqmPlanInsights -Path ".\slow-query.sqlplan" -ServerInstance "SQL01" `
-Database "AppDB" -InspectDatabase -OutFile ".\plan.json"Pair it with the offline, self-contained Plan Visualizer (Tools\PlanVisualizer\plan_visualizer_V4.html) — drop the JSON bundle in for an interactive diagram with the same findings. No network calls, nothing leaves your machine.
Automatically synchronize SQL logins from primary to secondary replicas in AlwaysOn Availability Groups:
# Install the standard job on EVERY replica (daily 2:00 AM, only the primary works)
Install-sqmStandardJob -Name AgLoginSync -AvailabilityGroupName "ProdAG"
# All standard jobs with their defaults
Install-sqmStandardJob -List
# Run sync immediately with backup
Sync-sqmLoginsToAlwaysOn -SqlInstance "SQL01" -AvailabilityGroupName "ProdAG" `
-Force -BackupLogins- -Force Mode: Update existing logins (password changes)
- SafeForceMode: Auto-exclude sa, SQL Agent Account, system logins
- -ForceIncludeOnly: Whitelist specific logins for updates
- Backup-Logins: Create rollback scripts before applying changes
- Listener SPN Checking: Get-sqmSpnReport now validates AlwaysOn listener SPNs
- UPN Support: Fixed service account handling for UPN format (user@domain.net)
- Smart AG Detection: Auto-detect primary/secondary replicas with warnings for multiple AGs
# Clone repository
git clone https://github.com/JankeUwe/sqmSQLTool.git
# Import module
Import-Module ./sqmSQLTool/sqmSQLTool.psd1 -ForceGet-Command -Module sqmSQLTool | Measure-Object
# Output: 163 functionsOn the first sqmSQLTool command of a session (at most once every 24 hours) the module checks
its install source (PSGallery, UNC share or local folder) for a newer version and offers to
install it: Yes / No (ask again later) / Skip this version. SQL Agent jobs, scheduled tasks and
-NonInteractive sessions are never prompted.
Update-sqmModule # check and update manually
Set-sqmConfig -UpdateMode Prompt # default: offer newer versions
Set-sqmConfig -UpdateMode Auto # install without asking (also in Agent jobs)
Set-sqmConfig -UpdateMode Off # no checkSync-sqmLoginsToAlwaysOn- Automated login synchronizationInstall-sqmStandardJob- Standard Agent jobs (AgLoginSync, AgLoginCompare) in one callNew-sqmAutoLoginSyncJob- Shortcut forInstall-sqmStandardJob -Name AgLoginSyncGet-sqmDistributedAgHealth- Distributed AG statusGet-sqmSpnReport- SPN validation including listenersComplete-sqmListenerMigration- Listener migration workflow
Invoke-sqmHealthReport- All checks in one call: one HTML report with prioritized findings, linked detail reports, optional ZIPGet-sqmPlanCacheReport- Top N plan cache statements by CPU, duration, reads, grants, spills, with .sqlplan exportGet-sqmPlanInsights- Execution plan analysis: CE mismatches, SARGability, spills, missing indexesGet-sqmIndexUsageReport- Unused, duplicate and overlapping indexes, heaps (read-only, DROP script commented out)Get-sqmFileLatencyReport- Read/write latency per database file, cumulative or live sampleGet-sqmWaitStatistics- SQL Server wait statisticsGet-sqmDiskSpaceReport- Disk utilization and growth trendsGrant-sqmVolumeAccess- Grants Authenticated Users, Administrators or any group NTFS rights on data volumes/folders, including folders with broken inheritance, inheritance downwards on/off; verifies every changeTest-sqmBackupStatus- Backup control: Full/Diff/Log age per database against thresholds, honours sqm_BackupExclude, flags databases created after the last backup runGet-sqmBackupExcludeReport- Report of sqm_BackupExclude: excluded databases with reason, who and since when (from the change log), orphaned and not yet registered databases, risk hintsGet-sqmDatabaseRestoreHistory- Last restore date per database, flags never-restored databasesGet-sqmMissingIndexes- Index recommendations with CREATE statementsGet-sqmAutoGrowthReport- Database autogrowth trackingGet-sqmIndexFragmentation- Index fragmentation analysisInvoke-sqmIndexOptimize- Index maintenance with sensible defaults: REORGANIZE 5-30 %, REBUILD ONLINE from 30 % with low-priority wait, per partition, time limit
Copy-sqmLogins- Transfer logins with password hash preservationGet-sqmSysadminAccounts- Enumerate sysadmin accountsGet-sqmADGroupMembers- Validate AD group membershipsGet-sqmTlsStatus- SQL Server TLS/SSL configurationInvoke-sqmLoginAudit- Login activity tracking
Export-sqmServerConfiguration- Full instance configuration exportCompare-sqmServerConfiguration- Instance comparisonExport-sqmAlwaysOnConfiguration- AG configuration exportExport-sqmDatabaseDocumentation- Database schema documentation
Complete documentation with examples for all 163 functions:
- HTML Reference: https://www.powershelldba.de/sqmsqltool/commands-en/
- GitHub Releases: https://github.com/JankeUwe/sqmSQLTool/releases
- SQL Server: 2016 or later
- PowerShell: 5.1 or 7.x
- dbatools: Latest version (installed as dependency)
- Operating System: Windows Server 2016+
- Permissions: sysadmin on SQL Server instances
Q: Can I use sqmSQLTool with SQL Server 2012 or 2014?
A: No. Minimum requirement is SQL Server 2016. Features like Distributed AGs require SQL Server 2019+.
Q: Do I need sysadmin rights for all functions?
A: Most functions require sysadmin. Some read-only functions (e.g., Get-sqmDiskSpaceReport) work with lower roles, but login synchronization and configuration export require sysadmin.
Q: How do I import the module in PowerShell 5.1 vs 7.x?
A: Same command works for both: Import-Module ./sqmSQLTool/sqmSQLTool.psd1. Module is compatible with .NET Framework 4.8 (PS 5.1) and .NET 6+ (PS 7.x).
Q: What if Sync-sqmLoginsToAlwaysOn fails with "Login already exists"?
A: Use -Force flag to update existing logins. Use -SafeForceMode to auto-exclude system accounts. Run with -WhatIf first to preview changes.
Q: Can I schedule login sync across multiple AG instances?
A: Yes. Run Install-sqmStandardJob -Name AgLoginSync on every replica. It creates a SQL Agent job that runs daily at 2:00 AM; on a secondary the step ends without doing anything, so after a failover the new primary takes over. The job only adds missing logins (-Force:$false), it never drops and recreates existing ones.
Q: How do I export AlwaysOn configuration for documentation?
A: Use Export-sqmAlwaysOnConfiguration -SqlInstance "SQL01" -OutputPath "C:\Exports". Generates HTML + CSV with replica status, listeners, and database sync state.
Q: Does the module support Azure SQL Managed Instance?
A: Limited support. AlwaysOn features don't apply. Use security/login functions (Get-sqmSysadminAccounts, Get-sqmTlsStatus) with caution due to API differences.
MIT License - See LICENSE file for details
Uwe Janke | Senior IT Specialist | SQL Server & PowerShell Automation
- GitHub: @JankeUwe
- Website: https://www.powershelldba.de