Friday, 8 November 2013

SQL instance discovery

Along time ago I wrote about making your own disk capacity tool, now i'll show you how to collect SQL instance. now most of you know that SQL browser can help with this however because of firewalls or just instance running on strange ports.
So can get the instance names and the version from the registry, sadly Microsoft never use the same place twice so here is my solution to get the result to text file.
for /f %i in (c:\list1.txt) do REG QUERY "\\%i\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" /v InstalledInstances |findstr /i "InstalledInstances" >>Instances.txt

for /f %i in (c:\list1.txt) do REG QUERY "\\%i\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\Setup" /v Edition |findstr /i "Edition" >>2005.txt

for /f %i in (c:\list1.txt) do REG QUERY "\\%i\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\Setup" /v Edition |findstr /i "Edition" >>2008.txt

for /f %i in (c:\list1.txt) do REG QUERY "\\%i\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup" /v Edition |findstr /i "Edition" >>2012.txt

for /f %i in (c:\list1.txt) do REG QUERY "\\%i\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\CurrentVersion" /v CurrentVersion |findstr /i "CurrentVersion" >>SQLExpress.txt

Hope you all find this useful for whatever reason you need to find the SQL edition or instance name without accessing the SQL for example when your systems are secure to prevent record changes but you need to know what patches to apply.

No comments: