Skip to content

Instantly share code, notes, and snippets.

@shadyrudy
Created June 14, 2023 21:20
Show Gist options
  • Save shadyrudy/d8d4d4926b80dece8cd524e0c68192f5 to your computer and use it in GitHub Desktop.
Save shadyrudy/d8d4d4926b80dece8cd524e0c68192f5 to your computer and use it in GitHub Desktop.
Get SQL Server AG Listener Name via Powershell
# 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