commands

^

Set-DbaTcpPort

Author @H0s0n77
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Set-DbaTcpPort on GitHub.
Want to see the Bill Of Health for this command? Check out Set-DbaTcpPort.

Synopsis

Changes the TCP port used by the specified SQL Server.

Description

This function changes the TCP port used by the specified SQL Server.

Be aware that the Database Engine begins listening on a new port only when restarted. So you have to restart the Database Engine that the new settings become effective.

Syntax

Set-DbaTcpPort
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-Credential] <PSCredential>]
    [-Port] <Int32[]>
    [[-IpAddress] <IPAddress[]>]
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Set-DbaTcpPort -SqlInstance sql2017 -Port 1433

Sets the port number 1433 for all IP Addresses on the default instance on sql2017. Prompts for confirmation.

Example: 2
PS C:\> Set-DbaTcpPort -SqlInstance winserver\sqlexpress -IpAddress 192.168.1.22 -Port 1433 -Confirm:$false

Sets the port number 1433 for IP 192.168.1.22 on the sqlexpress instance on winserver. Does not prompt for confirmation.

Example: 3
PS C:\> Set-DbaTcpPort -SqlInstance sql2017, sql2019 -port 1337 -Credential ad\dba -Force

Sets the port number 1337 for all IP Addresses on SqlInstance sql2017 and sql2019 using the credentials for ad\dba. Prompts for confirmation. Restarts the service.

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required True
Pipeline true (ByValue)
Default Value
-Port

TCPPort that SQLService should listen on.

Alias
Required True
Pipeline false
Default Value

Optional Parameters

-Credential

Credential object used to connect to the Windows server itself as a different user (like SQL Configuration Manager).

Alias
Required False
Pipeline false
Default Value
-IpAddress

Ip address to which the change should apply, if omitted AllIp (0.0.0.0) will be changed with the new port number.

Alias
Required False
Pipeline false
Default Value
-Force

Will restart SQL Server and SQL Server Agent service to apply the change.

Alias
Required False
Pipeline false
Default Value False
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

Alias cf
Required False
Pipeline false
Default Value