Execution Flow
ConfirmImpact=High — This operation drops the listener from the source AG before re-creating it on the target. If the ADD step fails, the listener is no longer associated with either AG. Always run with
-WhatIf first and ensure DNS TTL is set low before executing.The function writes a TXT report to the output directory containing
nslookup and sqlcmd commands to verify DNS propagation and connectivity after the move. DNS update is required if the new AG's primary replica is on a different IP.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Required | SQL Server instance hosting both AGs (must be primary or have WSFC visibility). |
| -SqlCredential | PSCredential | Optional | SQL authentication credentials. |
| -SourceAvailabilityGroup | String | Required | Name of the AG currently owning the listener. |
| -TargetAvailabilityGroup | String | Required | Name of the AG that will receive the listener. |
| -ListenerName | String | Required | DNS name of the listener to migrate. |
| -OutputPath | String | Optional | Directory for the TXT report. Default: current directory. |
| -EnableException | Switch | Optional | Throw exceptions immediately on error. |
| -WhatIf | Switch | Optional | Preview actions without making any changes. |
| -Confirm | Switch | Optional | Prompt before each high-impact action. |
Return Value
Returns a single PSCustomObject with: Status, SourceAg, TargetAg, ListenerName, ListenerIp, ListenerPort, DnsUpdateRequired, ReportFile, NextSteps.
Examples
Example 1 — WhatIf first (recommended)
Move-sqmAlwaysOnListener -SqlInstance "SQL01" `
-SourceAvailabilityGroup "AG_Finance" `
-TargetAvailabilityGroup "AG_Finance_DR" `
-ListenerName "ag-finance-listener" `
-WhatIf
Example 2 — Execute the migration
Move-sqmAlwaysOnListener -SqlInstance "SQL01" `
-SourceAvailabilityGroup "AG_Finance" `
-TargetAvailabilityGroup "AG_Finance_DR" `
-ListenerName "ag-finance-listener" `
-OutputPath "C:\Reports\AG" -Confirm
Example 3 — Capture result and check DNS requirement
$result = Move-sqmAlwaysOnListener -SqlInstance "SQL01" `
-SourceAvailabilityGroup "AG_Old" -TargetAvailabilityGroup "AG_New" `
-ListenerName "my-listener"
if ($result.DnsUpdateRequired) {
Write-Host "Update DNS — see: $($result.ReportFile)"
}