New-SqlAvailabilityGroupListener
Creates an availability group listener and attaches it to an availability group.
Syntax
ByPath (Default)
New-SqlAvailabilityGroupListener
[-Name] <String>
[[-Path] <String>]
[-DhcpSubnet <String>]
[-StaticIp <String[]>]
[-Port <Int32>]
[-Script]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
ByObject
New-SqlAvailabilityGroupListener
[-Name] <String>
[-InputObject] <AvailabilityGroup>
[-DhcpSubnet <String>]
[-StaticIp <String[]>]
[-Port <Int32>]
[-Script]
[-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.
Parameters
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
Type: | SwitchParameter |
Default value: | False |
Supports wildcards: | False |
DontShow: | False |
Aliases: | cf |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | 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.
Parameter properties
Type: | String |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-InputObject
Specifies the availability group, as an AvailabilityGroup object, to which this cmdlet attaches the listener.
Parameter properties
Type: | AvailabilityGroup |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
ByObject
Position: | 3 |
Mandatory: | True |
Value from pipeline: | True |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Name
Specifies a name for the listener.
Parameter properties
Type: | String |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | 2 |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | 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.
Parameter properties
Type: | String |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
ByPath
Position: | 3 |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Port
Specifies the port on which the listener listens for connections. The default port is TCP port 1433.
Parameter properties
Type: | Int32 |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Script
Indicates that this cmdlet returns a Transact-SQL script that performs the task that this cmdlet performs.
Parameter properties
Type: | SwitchParameter |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | 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.
Parameter properties
Type: | String[] |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Parameter properties
Type: | SwitchParameter |
Default value: | False |
Supports wildcards: | False |
DontShow: | False |
Aliases: | wi |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.