dbatools is a free PowerShell module with over 200 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Get-DbaTcpPort

This command returns the TCP port used by the specified SQL Server. By default, only the TCP port used by the specified SQL Server is returned. If -Detailed is specified, server name, IPAddress (ipv4 and ipv6), port number and if the port assignment is static.

Screenshots

get-dbatcpport

Examples

To return just the port number for the default instance on sqlserver2014a

Get-DbaTcpPort -SqlServer sqlserver2014a

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

Get-DbaTcpPort -SqlServer winserver\sqlexpress, sql2016

To return an object with server name, IPAddress (ipv4 and ipv6), port and static ($true/$false) for sqlserver2014a and sql2016

Get-DbaTcpPort -SqlServer sqlserver2014a, sql2016 -Detailed

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

Get-SqlRegisteredServerName -SqlServer sql2014 | Get-DbaTcpPort -NoIpV6 -Detailed -Verbose

Notes

When using the -Detailed parameter, SqlWmi is invoked. Our apologies if some results don’t return properly; SqlWmi can be a bit buggy.

Get-Help

From PowerShell, execute Get-Help Get-DbaTcpPort -Detailed for more information on this function.

Source Code

Want to see the source code? View Get-DbaTcpPort.ps1 on GitHub
 

Related commands