THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Buck Woody

Carpe Datum!

List SQL Server Instances using the Registry

I read this interesting article on using PowerShell and the registry, and thought I would modify his information a bit to list the SQL Server Instances on a box. The interesting thing about listing instances this was is that you can touch remote machines, find the instances when they are off and so on. Anyway, here’s the scriptlet I used to find the Instances on my system:

$MachineName = '.'

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $MachineName)

$regKey= $reg.OpenSubKey("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL" )


You can read more of his article to find out the reason for the remote registry call and so forth – there are also security implications here for being able to read the registry.

Script Disclaimer, for people who need to be told this sort of thing:

Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. Yes, there are always multiple ways to do things, and this script may not work in every situation, for everything. It’s just a script, people. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately.

Published Wednesday, March 31, 2010 7:41 AM by BuckWoody



AllenMWhite said:

You can also get the Instance names on server 'SQLTBWS' like this:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO")  | Out-Null

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement")  | Out-Null

$m = New-Object ('Microsoft.SqlServer.Management.Smo.WMI.ManagedComputer') 'SQLTBWS'                              

$m.ServerInstances | ForEach-Object { $m.Name + '\' + $_.Name


(Test - your mileage may vary.)

March 31, 2010 12:45 PM

BuckWoody said:

Thanks, Allen!  I posted three or four versions of what you have there (I think you helped me on them) over at Always good to have lots of ways to do something!

March 31, 2010 1:25 PM

Chad Miller said:

Here's another method using the registry provider:

Get-ItemProperty HKLM:\"Software\Microsoft\Microsoft SQL Server\Instance Names\SQL*" | Get-Member SQL* | Select Name

March 31, 2010 9:17 PM

André Kamman said:

I've used the very same info a while ago to create a script to scan the entire network for SQL Servers. It can also find SQL Server 2000 versions which are stored in a different way.

You can find the script here :

April 1, 2010 3:18 AM
New Comments to this post are disabled

About BuckWoody

This Blog


Privacy Statement