How to find the port where SQL server is listning using PowerShell

Posted on Posted in Scripts

Here is the PowerShell code snippet to find the port where the SQL server is listing:

 

$SQLPort = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$InstanceName\MSSQLServer\SuperSocketNetLib\Tcp").TcpPort
Write-Host "The SQl Server TCP/IP port is $SQLPort"


# HostPort is for the XML config files of Tomcat
$HostPort = $env:computername+':'+$SQlPort

Leave a Reply

Your email address will not be published. Required fields are marked *