New-​Sql​Availability​Group​Listener

Creates an availability group listener and attaches it to an availability group.

Syntax

New-SqlAvailabilityGroupListener
   [-Name] <String>
   [[-Path] <String>]
   [-DhcpSubnet <String>]
   [-StaticIp <String[]>]
   [-Port <Int32>]
   [-Script]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-SqlAvailabilityGroupListener
   [-Name] <String>
   [-InputObject] <AvailabilityGroup>
   [-DhcpSubnet <String>]
   [-StaticIp <String[]>]
   [-Port <Int32>]
   [-Script]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

The New-SqlAvailabilityGroupListener cmdlet creates an availability group listener, and attaches it to an availability group. Run this cmdlet on the server instance that hosts the primary replica.

Examples

Example 1: Create a listener for an availability group

PS C:\> New-SqlAvailabilityGroupListener -Name "MainListener" -Path "SQLSERVER:\SQL\PrimaryServer\InstanceName\AvailabilityGroups\MainAG"

This command creates an availability group listener named MainListener for the availability group named MainAG. This listener acquires a virtual IP address by using DHCP. Run this command on the server instance that hosts the primary replica.

Example 2: Create a listener for an availability group that has a non-default port

PS C:\> New-SqlAvailabilityGroupListener -Name "MainListener" -Path "SQLSERVER:\SQL\PrimaryServer\InstanceName\AvailabilityGroups\MainAG" -Port 1434

This command creates an availability group listener named MainListener for the availability group named MainAG. As in the previous example, this listener acquires a virtual IP address by using DHCP. This example assigns the port 1434 on which it listens.

Example 3: Create a listener for an availability group that uses DHCP

PS C:\> New-SqlAvailabilityGroupListener -Name "MainListener" -DhcpSubnet "192.169.0.1/255.255.252.0" -Path "SQLSERVER:\SQL\PrimaryServer\InstanceName\AvailabilityGroups\MainAG"

This command creates an availability group listener named MainListener for the availability group named MainAG. This listener acquires a virtual IP address in the specified subnet by using DHCP.

Example 4: Create a listener for an availability group that uses a static address

PS C:\> New-SqlAvailabilityGroupListener -Name "MainListener" -StaticIp "192.168.3.1/255.255.252.0" -Path "SQLSERVER:\Sql\Computer\Instance\AvailabilityGroups\MainAG"

This command creates an availability group listener named MainListener for the availability group named MainAG. This listener uses the IPv4 address specified by the StaticIp parameter as its virtual IP address.

Example 5: Create a script that creates a listener

PS C:\> New-SqlAvailabilityGroupListener -Name "MainListener" -Path "SQLSERVER:\Sql\Computer\Instance\AvailabilityGroups\MainAG" -Script

This command creates a Transact-SQL script that creates an availability group listener named MainListener for the availability group named MainAG. The command does not create a listener.

Required Parameters

-InputObject

Specifies the availability group, as an AvailabilityGroup object, to which this cmdlet attaches the listener.

Type:AvailabilityGroup
Position:2
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-Name

Specifies a name for the listener.

Type:String
Position:1
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Optional Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False
-DhcpSubnet

Specifies an IPv4 address and subnet mask of a network. The listener determines the address on this network by using DHCP. Specify the address in for following format: 192.168.0.1\255.255.255.0.

If you specify this parameter, do not specify the StaticIp parameter.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-InformationAction

Specifies how this cmdlet responds to an information event.

The acceptable values for this parameter are:

  • Continue
  • Ignore
  • Inquire
  • SilentlyContinue
  • Stop
  • Suspend
Type:ActionPreference
Aliases:infa
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-InformationVariable

Specifies an information variable.

Type:String
Aliases:iv
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Path

Specifies the path of the availability group to which this cmdlet attaches a listener. If you do not specify this parameter, this cmdlet uses current working location.

Type:String
Position:2
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Port

Specifies the port on which the listener listens for connections. The default port is TCP port 1433.

Type:Int32
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Script

Indicates that this cmdlet returns a Transact-SQL script that performs the task that this cmdlet performs.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-StaticIp

Specifies an array of addresses. Each address entry is either an IPv4 address and subnet mask or an IPv6 address. The listener listens on the addresses that this parameter specifies.

If you specify this parameter, do not specify the DhcpSubnet parameter.

Type:String[]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

Microsoft.SqlServer.Management.Smo.AvailabilityGroup