Category Archives: Databases

List SQL Servers On Network

A list of servers can be obtained using windows command prompt (cmd) or powershell (ps).  CMD and PS both provide Server Name and Instance Name, however, powershell provides two additional fields: IsClustered, and SQL Server Version.  One challenge I have noticed is that running these commands from my local machine only returns a short list with names that look like computer names and not server names.  I had to run the commands from a production server, a QA server, and a development server to obtain the server lists from those environments.  There must be some network separation between them, which I am still investigating.

CMD: OSQL -L or SQLCMD -L

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