Created
June 14, 2023 21:20
-
-
Save shadyrudy/d8d4d4926b80dece8cd524e0c68192f5 to your computer and use it in GitHub Desktop.
Get SQL Server AG Listener Name via Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import SQL Server module | |
Import-Module "SQLPS" -DisableNameChecking | |
# Variables | |
$ServerName = "YourServerName" # Enter your server name here | |
$Server = New-Object Microsoft.SqlServer.Management.Smo.Server $ServerName | |
# Get the availability groups | |
$AvailabilityGroups = $Server.AvailabilityGroups | |
# Print the names of the Availability Group Listeners | |
foreach($AG in $AvailabilityGroups) | |
{ | |
foreach($Listener in $AG.AvailabilityGroupListeners) | |
{ | |
Write-Output $Listener.Name | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment