Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL Server 13
#SQLServer 7
DBA 7
BRH 5
indexes 4
Power Shell 2
object naming 1
joke 1
whitespaces 1
training 1

Archive · View All
July 2011 6
August 2011 4
March 2012 2
February 2012 1
December 2011 1
October 2011 1
September 2011 1

Szymon Wojcik's Blog

Enumerating SQL Server instances in a network with Power Shell

Aug 8 2011 12:55AM by Szymon Wojcik   

Ever wondered how many SQL Server instances are there in your network? Or maybe you wanted to check a settings or run a script on all of them? Of course you can use Registered Servers functionality and run a query on all servers in a group, but this can save you the pain of adding all servers one by one.

Since Power Shell builds on .NET framework, you are free to use all the mechanisms available in it. The one we are interested in here is SqlDataSourceEnumerator, which allows you to enumerate all available instances of SQL Server in a local network. The only prerequisite is that servers must have SQL Server Browser service running and the task is completed by the following one-liner:

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

The output you get is a table consisting of four columns – server and instance name, version and information if the server is clustered.

ServerName                                 InstanceName                               IsClustered                                Version                                 
----------                                 ------------                               -----------                                -------                                   
PHOBOS-MOBILNY                                                                        No                                         9.00.4035.00                              

Now take a simple extension of it and you are able to connect to every single SQL Server in your network. It will give you the list in standard SERVER\INSTANCE format. Then you can expand it further using SMO or Power Shell snap-in and you will get all the information you need from all servers at the same time.

[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()  | % {if ($_.InstanceName -eq "".ToString) { $_.ServerName + "\" + $_.InstanceName} else { $_.ServerName }}

I’m awaiting - as always – your feedback, what’s good and what still needs to be improved. Or maybe there’s just something you would like to share.

Tags: Power Shell, DBA, SQL Server, multi-server administration,


Szymon Wojcik
67 · 3% · 839
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

2  Comments  

  • Hello,

    I prefer to use SmoApplication.EnumAvailableSqlServers methods as there is a Locale property in the returned datatable which i am using when i am wanting to replace the name of the locale computer by "." in the full name of the instance. Disadvantages : to load the Microsoft.SqlServer.Management.Smo.dll and a little longer for execution Advantages : the locale colum and 3 columns to describe the name of the SQL Server instance In fact, both methods are using the same code in an internal way

    commented on Aug 17 2011 11:58AM
    Patrick Lambin
    162 · 1% · 296
  • Thanks for the info, didn't know that.

    commented on Aug 22 2011 8:32AM
    Szymon Wojcik
    67 · 3% · 839

Your Comment


Sign Up or Login to post a comment.

"Enumerating SQL Server instances in a network with Power Shell" rated 5 out of 5 by 1 readers
Enumerating SQL Server instances in a network with Power Shell , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]