In this recipe, we will list all SQL Server instances in the local network.
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Let's use the
Start-Service
cmdlet to start SQLBrowser:Import-Module SQLPS -DisableNameChecking #sql browser must be installed and running Start-Service "SQLBrowser"
Next, you need to create a
ManagedComputer
object to get access to instances. Type the following script and run it:$instanceName = "KERRIGAN" $managedComputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' $instanceName #list server instances $managedComputer.ServerInstances
Your result should look similar to the one shown in the following screenshot:
Note that
$managedComputer.ServerInstances
gives you not only instance names, but also additional properties such asServerProtocols...