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.
Returns the TCP port used by the specified SQL Server.
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.
Get-DbaTcpPort
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Credential] <PSCredential>]
[-All]
[-ExcludeIpv6]
[-EnableException]
[<CommonParameters>]
PS C:\> Get-DbaTcpPort -SqlInstance sqlserver2014a
Returns just the port number for the default instance on sqlserver2014a.
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.
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.
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.
The target SQL Server instance or instances.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
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 object used to connect to the Computer as a different user
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
If this switch is enabled, IPv6 information is excluded from All output.
Alias | Ipv4 |
Required | False |
Pipeline | false |
Default Value | False |
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 |