2010-08-31

Getting the TCP port of all instances on a machine

So... we run multiple SQL instances per physical server. There also seems to be a firewall issue between my laptop and the environment that prevents port resolution for those instances. So, I decided to whip up a little Powershell script.

$results = @()
$MachineObject = new-object ('Microsoft.SqlServer.Management.Smo.WMI.ManagedComputer') .
foreach ($instance in $MachineObject.ServerInstances) {
   $return = '' | select Instance, Port
   $return.Instance = $instance.name
   $return.Port = $instance.ServerProtocols['Tcp'].IPAddresses['IPAll'].IPAddressProperties['TcpPort'].Value
   $results += $return 
}
$results | format-table

Don't run with scissors.

No comments:

Post a Comment