Current SQL Server instances

You should also check how many SQL Server instances are installed on the server and their names for non-default instances. To do this, we can use SQL Management Objects (SMO) with PowerShell and then use the ServerInstances member property:

#below should be a single line of code
$managedComputer = New-Object "Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer" $servername

#list SQL Server instances
$managedComputer.ServerInstances |
Select-Object Name, State, ServerProtocols, Urn |
Format-List

The preceding script simply lists the instances installed. Note that MSSQLSERVER is the name you'll see for a default instance:

Get PowerShell for SQL Server Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.