New-SqlAvailabilityGroupListener
Creates an availability group listener and attaches it to an availability group.
语法
ByPath (默认值)
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>]
说明
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.
示例
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.
参数
-Confirm
Prompts you for confirmation before running the cmdlet.
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
别名: | cf |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | 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.
参数属性
类型: | String |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-InputObject
Specifies the availability group, as an AvailabilityGroup object, to which this cmdlet attaches the listener.
参数属性
类型: | AvailabilityGroup |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
ByObject
Position: | 3 |
必需: | True |
来自管道的值: | True |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Name
Specifies a name for the listener.
参数属性
类型: | String |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | 2 |
必需: | True |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | 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.
参数属性
类型: | String |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
ByPath
Position: | 3 |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Port
Specifies the port on which the listener listens for connections. The default port is TCP port 1433.
参数属性
类型: | Int32 |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Script
Indicates that this cmdlet returns a Transact-SQL script that performs the task that this cmdlet performs.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | 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.
参数属性
类型: | String[] |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
别名: | wi |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | 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.