June 15, 2007 at 8:05 am
Been struggling with this for a few hours now.
I know how to find all sql servers on a domain (osql -L) easy enough.
and I know how to find the version of sql server from a known server with the dos reg /query commands. But does anyone have any scripts to find both the server and version via either osql, isql or AD or anything?
See, my company has about 160 SQL servers (I'm new, this isn't my fault), many of which are msde or SQL express editions on workstations, and I need to find out which Server versions are on which version number. It's tricky but I just need a servername...version list.
June 19, 2007 at 12:29 am
It can be handled this way. Write a DOS program to do the following
1. use OSQL -L to list the servers/machines running sql server and move the list to a text file.
2. read the name one by one from the text file and find the version of the machine name read.
But ensure that you have access to all the sql servers placed in your work environment so that nothing fails. also try to handle errors as much as possible.
Cheers,
Sugeshkumar Rajendran
SQL Server MVP
http://sugeshkr.blogspot.com
June 19, 2007 at 5:58 am
Sugesh,
Do you have any batch code that will actually do this?
--Jeff Moden
Change is inevitable... Change for the better is not.
June 19, 2007 at 6:17 am
I currently don't have one. But sure that this can be written and used in huge environments.
Cheers,
Sugeshkumar Rajendran
SQL Server MVP
http://sugeshkr.blogspot.com
June 19, 2007 at 7:01 am
Steve,
Would you post the "dos reg /query" code you're using to find the version? Then I'll see what I can do...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 19, 2007 at 7:17 am
sure, I actually was able to do it all in dos (with osql)
but it is an ugly file. I didn't have time to pretty up the results
but here is the code to actually extract all the server names and grab
the sql version (note, basically if the registry key isn't there then this is
an msde version, clunky I know, but it works for my purposes). I still would
like to find a way to do this whole thing in SQL but without cursors (I simply
REFUSE to write a cursor query, just out of spite ), I couldn't find a way
to do it (although testing, I did find a query that I had almost working WITH a cursor)
2 step process:
1. osql -L out a text file of the names of all servers that report sql on the domain.
NOTE: I called this sqlenum.txt
2. create a batch file (in the same dir) with this code in it:
FOR /f "delims=|" %%a IN (sqlenum.txt) DO (
REG QUERY \\%%a\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName /V COMPUTERNAME >>\\[your local machine name]\c$\sql_machines\SQL_VER.TXT
REG QUERY \\%%a\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion /V CSDVERSION >>\\[your local machine name]\c$\sql_machines\SQL_VER.TXT
ECHO '**************************' >> \\[your local machine name]\c$\sql_machines\SQL_VER.TXT
)
Code NOTE:
******Replace [your local machine name] with .......your local machine name.
NOTE: This will return the machine name and the sql version (if it is available)
NOTE1: the REG QUERY lines are suppose to be all one line but this forum doesn't allow me to do that, so make sure it's all one line in your text.
NOTE2: This query can take a little while as if the machine is offline it will need to do the whole 30 second timeout thing.
June 19, 2007 at 10:39 am
Note that servers can mark themselves as "hidden" from -L and if any routers block 1434, this won't work either.
If you have SMS or someone can run a query, the search for MSSQL% in the services list is a more accurate way.
June 19, 2007 at 12:22 pm
Steve Jones,
I'm a bit ignorant here... how do you "run a query, the search for MSSQQL% in the services list ia a more accurate way"? Where is that "services List" you speak of? (SQL Server 2000 and 2005)
--Jeff Moden
Change is inevitable... Change for the better is not.
June 19, 2007 at 12:24 pm
Thanks, Steve Hare...
I'll see what I can hammer out but I'm also interested in what Steve Jones said about searching a "services list" for MSSQL%. I just need to find out what he's talking about because of the "hidden" thing he talked about.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 19, 2007 at 12:53 pm
I think he means (this is a big guess), you can query the registry for services that match MSSQL%.
June 19, 2007 at 1:33 pm
USE MASTER
SELECT SUBSTRING(@@SERVERNAME,1,40), SUBSTRING(@@VERSION,1,300)
May 31 2003 16:08:15
Copyright (c) 1988-2003 Microsoft Corporation
Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
June 20, 2007 at 4:03 am
Cat,
This is what i told before i just said the way to get it and you haev coded. Great. hats off Buddy.
Cheers,
Sugeshkumar Rajendran
SQL Server MVP
http://sugeshkr.blogspot.com
June 20, 2007 at 7:14 am
Check this site for SQLRecon. It is a free sql server scanner.
http://www.sqlsecurity.com/Tools/FreeTools/tabid/65/Default.aspx
June 21, 2007 at 6:59 am
I did try that tool once before, pretty good, but it does some pretty scary scans on the network and get's our Firewall Admin all in a tizzy. I have to email him 10 minutes before I do one or he goes insane with all the port scans happening. Even in stealth mode it flags multiple intrusion/detection alerts on a network.
June 21, 2007 at 8:03 am
I have been using SQLPing 3.0 that I found at the link below to discover servers, but it is GUI based, so it is hard to automate. It does do a good job of finding SQL Servers in an IP address range using about 8 different methods of discovery, and allows export of the information to an XML file. It has a lot of the information you are looking for, and it will even find SQL Server where it is not currently running.
http://www.sqlsecurity.com/Tools/FreeTools/tabid/65/Default.aspx
You can use this script to parse the @@version global variable on each server to get the version information:
Parse @@VERSION
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=84713
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply