< Back

Get-DbaTcpPort

Mon Jan 13, 2020 11:43 am

NAME Get-DbaTcpPort



SYNOPSIS

Returns the TCP port used by the specified SQL Server.





SYNTAX

Get-DbaTcpPort [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]

<Pscredential>] [[-Credential] <Pscredential>] [-All <Switch>] [-ExcludeIpv6 <Switch>] [-EnableException <Switch>]

[<CommonParameters>]





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.





PARAMETERS

-All [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Credential [<Pscredential>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeIpv6 [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

Allows you to connect to servers using alternate Windows credentials



$scred = Get-Credential, then pass $scred object to the -SqlCredential parameter.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: SQLWMI, tcp

Author: Chrissy LeMaire (@cl), netnerds.net



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- 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.



RELATED LINKS

https://dbatools.io/Get-DbaTcpPort