Listing SQL Server instances
In this recipe, we will list all SQL Server instances in the local network.
Getting ready
Log in to the server that has your SQL Server development instance as an administrator.
How to do it...
Let's look at the steps to list your SQL Server instances:
Open PowerShell ISE as administrator.
Let's use the
Start-Service
cmdlet to start the SQL Browser service:Import-Module SQLPS -DisableNameChecking #out of the box, the SQLBrowser is disabled. To enable: Set-Service SQLBrowser -StartupType Automatic #sql browser must be installed and running for us #to discover SQL Server instances Start-Service "SQLBrowser"
Next, you need to create a
ManagedComputer
object to get access to instances. Type the following script and run:$instanceName = "localhost" $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...