Commands / Export-sqmAlwaysOnConfiguration
Export-sqmAlwaysOnConfiguration
Always On sqmSQLTool v1.8.2+ · Export ✓ -WhatIf supported  🛠 Pipeline
Reads the static AG configuration (not runtime status) for one or more SQL Server instances and exports it as a formatted TXT report and CSV file.

Per AG, the export includes: name, backup preference, failure condition level, health-check timeout, DB-failover and distributed-AG flags, all replicas with their availability mode / failover mode / ReadableSecondary setting / backup priority, listener DNS name, port and IP addresses, and the list of member databases.

FI-TS compliance check: ReadableSecondary must be NO on all replicas. Any replica with READ_ONLY, ALL, or any non-NO value triggers a Write-Warning and sets Status = 'Warning' on the result object. Use -NoWarning to suppress the console warning (the status still reflects the issue).

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestring[]Optional$env:COMPUTERNAMEOne or more instances. Pipeline-capable. Processed sequentially.
-SqlCredentialPSCredentialOptionalUsed for all instance connections.
-OutputPathstringOptionalC:\System\WinSrvLog\MSSQLOutput directory for TXT and CSV files. Created automatically if missing.
-NoWarningswitchSwitch$falseSuppress Write-Warning for FI-TS violations. Status property still reflects the issue.
-NoOpenswitchSwitch$falseDo not auto-open the TXT report after creation.
-EnableExceptionswitchSwitch$falseRe-throw errors instead of recording them in the result object.
-WhatIf / -ConfirmswitchOptionalShouldProcess (ConfirmImpact: None) guards file-write step. -WhatIf skips TXT/CSV creation.

Execution Flow

START dbatools installed? NO throw: dbatools not found YES -SqlInstance provided? NO → Default: $env:COMPUTERNAME foreach $instance in $SqlInstance AGs found on instance? NO add empty result continue YES Query AG config + member databases sys.availability_groups, replicas, listeners, IPs | sys.availability_databases_cluster per AG FI-TS check: ReadableSecondary != NO? → Write-Warning per replica (unless -NoWarning) | log WARNING ShouldProcess? (ConfirmImpact: None) NO WhatIf: log files = $null YES Ensure OutputPath → Write TXT + CSV AlwaysOnConfiguration_<inst>_<date>.txt / .csv | open TXT (unless -NoOpen) Add result to $allInstanceResults Status: OK | Warning (FI-TS issues) | Error (catch → add error result) Return $allInstanceResults [PSCustomObject[]] SqlInstance, AgCount, ReplicaCount, ReadableSecondaryCount, Status, TxtFile, CsvFile DONE

Examples

Export AG configuration from SQL01 (warns if ReadableSecondary != NO)
Export-sqmAlwaysOnConfiguration -SqlInstance "SQL01"
Export to a custom path, suppress FI-TS warnings, do not open the report
Export-sqmAlwaysOnConfiguration -SqlInstance "SQL01" -OutputPath "D:\Reports" -NoWarning -NoOpen
Pipeline: export configuration from multiple instances
"SQL01","SQL02","SQL03" | Export-sqmAlwaysOnConfiguration -NoOpen