Instances and Ports with PowerShell

Just a quick post and a day late for #SQLNewBlogger There are some excellent posts on that hashtag and I recommend that you read them

When you know a server name but not the name of the instances or the ports that they are using this function will be of use

Shows the Instances and the Port Numbers on a SQL Server

This function will show the Instances and the Port Numbers on a SQL Server using WMI

The Server Name

Get-SQLInstancesPort Fade2Black

This will display the instances and the port numbers on the server Fade2Black
AUTHOR: Rob Sewell
DATE: 22/04/2015

function Get-SQLInstancesPort {

    param ([string]$Server)

    $mc = new-object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer $Server
    $Instances = $mc.ServerInstances

    foreach ($Instance in $Instances) {
        $port = @{Name = "Port"; Expression = {$_.ServerProtocols['Tcp'].IPAddresses['IPAll'].IPAddressProperties['TcpPort'].Value}}
        $Parent = @{Name = "Parent"; Expression = {$_.Parent.Name}}
        $Instance|Select $Parent, Name, $Port

4 thoughts on “Instances and Ports with PowerShell

  1. Rob,

    How could you modify this script to pull in named instance name or name for default instance?

    Ex. ServerName\InstanceName
    Computer Name

Leave a Reply to SQLDBAwithTheBeard Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.