DaveWentzel.com            All Things Data

DetermineSQLServerTCPPort


the alternate (simpler) easier method to the below (and can be run on the command line) is


get-content 'c:\program files\Microsoft SQL server\MSSQL\LOG\ERRORLOG' | select-string "listening"




  1.     $server = New-Object -comobject "SQLDMO.SQLServer" 

  2.      


  1.     $server.loginsecure = $TRUE 

  2.     $server.connect("server_instance") 

  3.     $server.registry.tcpport 

  4.     $server.close()  

or we can use WMI


$WQL = "SELECT PropertyStrVal "


$WQL += "FROM ServerNetworkProtocolProperty "


$WQL += "WHERE InstanceName = '$instance' AND "


$WQL += "IPAddressName = 'IPAll' AND "


$WQL += "PropertyName = 'TcpPort' AND "


$WQL += "ProtocolName = 'Tcp'"


$WMInamespace = 'root\Microsoft\SqlServer\ComputerManagement'


Get-WmiObject -query $WQL -computerName $computer -namespace $WMInamespace |


ForEach-Object { $_.PropertyStrVal }


 


PowerShell Home

Add new comment