commands

^

Get-DbaTcpPort

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

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

Synopsis

Returns the TCP port used by the specified SQL Server.

Description

By default, this function returns just the TCP port used by the specified SQL Server.

If -All is specified, the server name, IPAddress (ipv4 and ipv6), port number and an indicator of whether or not the port assignment is static are returned.

Remote sqlwmi is used by default. If this doesn't work, then remoting is used. If neither work, it defaults to T-SQL which can provide only the port.

Syntax

Get-DbaTcpPort
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Credential] <PSCredential>]
    [-All]
    [-ExcludeIpv6]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaTcpPort -SqlInstance sqlserver2014a

Returns just the port number for the default instance on sqlserver2014a.

Example: 2
PS C:\> Get-DbaTcpPort -SqlInstance winserver\sqlexpress, sql2016

Returns an object with server name and port number for the sqlexpress on winserver and the default instance on sql2016.

Example: 3
PS C:\> Get-DbaTcpPort -SqlInstance sqlserver2014a, sql2016 -All

Returns an object with server name, IPAddress (ipv4 and ipv6), port and static ($true/$false) for sqlserver2014a and sql2016.
Remote sqlwmi is used by default. If this doesn't work, then remoting is used. If neither work, it defaults to T-SQL which can provide only the port.

Example: 4
PS C:\> Get-DbaRegServer -SqlInstance sql2014 | Get-DbaTcpPort -ExcludeIpv6 -All

Returns an object with server name, IPAddress (just ipv4), port and static ($true/$false) for every server listed in the Central Management Server on sql2014.

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-SqlCredential

Allows you to connect to servers using alternate Windows credentials
$scred = Get-Credential, then pass $scred object to the -SqlCredential parameter.

Alias
Required False
Pipeline false
Default Value
-Credential

Credential object used to connect to the Computer as a different user

Alias
Required False
Pipeline false
Default Value
-All

If this switch is enabled, an object with server name, IPAddress (ipv4 and ipv6), port and static ($true/$false) for one or more SQL Servers is returned.

Alias
Required False
Pipeline false
Default Value False
-ExcludeIpv6

If this switch is enabled, IPv6 information is excluded from All output.

Alias Ipv4
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