PowerShell: How to list all SQL Servers on the network?


It’s a one line code. Make sure you run this code on a SQL server. OR on your computer where SQL Admin Console is installed.

Note: Make sure SQL Browser service is started on the computer you are running this code.

Open PoweShell, copy/paste this line:

[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()

That is it. Here is the sample Output:

A method called GetDataSources retrieves a DataTable containing information about all visible SQL Server instances in the network from SQL Server 2000 onwards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s