Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Get SQL Server version of each instance installed

Reply
Thread Tools Display Modes

Get SQL Server version of each instance installed

 
 
Carlos Felipe França da Fonseca
Guest
Posts: n/a

 
      09-18-2008
I'm looking for a way to get the version of each SQL Server instances
installed locally on a server.
Does anybody know the best way of doing that?

Thanks,

Felipe


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      09-18-2008
Felipe wrote:

> I'm looking for a way to get the version of each SQL Server instances
> installed locally on a server.
> Does anybody know the best way of doing that?
>


I use a VBScript program. You would need a connection string for each
instance.
===========
' Retrieve SQL Server version.

Option Explicit

Dim strConnect, adoConnection, adoRecordset, objShell
Dim strVersion, strLevel, strEdition

' Construct connection string for PocketLunch database.
strConnect = "DRIVER=SQL Server;" _
& "Trusted_Connection=Yes;" _
& "DATABASE=Master;" _
& "SERVER=MyServer\MyInstance"

' Create ADO objects and connect to PocketLunch database.
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.ConnectionString = strConnect
adoConnection.Open

Set adoRecordset = CreateObject("ADODB.Recordset")
Set adoRecordset.ActiveConnection = adoConnection

' Retrieve balances for each account as of specified date.
adoRecordset.Source = "SELECT SERVERPROPERTY('productversion') AS Version, "
_
& "SERVERPROPERTY('productlevel') AS Level, " _
& "SERVERPROPERTY('edition') AS Edition"
adoRecordset.Open

' Enumerate account balances.
Do Until adoRecordset.EOF
strVersion = adoRecordset.Fields("Version").Value
strLevel = adoRecordset.Fields("Level").Value
strEdition = adoRecordset.Fields("Edition").Value
Wscript.Echo "Version: " & strVersion
Wscript.Echo "Level: " & strLevel
Wscript.Echo "Edition: " & strEdition
adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close
adoConnection.Close
==========
Otherwise, you can run the query (the Source property of the ADO Recordset
object above) with a command line tool or GUI.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
Carlos Felipe França da Fonseca
Guest
Posts: n/a

 
      09-18-2008
Thanks for your reply, Richard.

I'm going to run this solution on many servers, locally and monthly using
Tivoli monitoring. The reason of running that is for auditing purposes.
The problem is that I don't know how many instances each server is running.
So, we'll need to discover how many instances the server is running and also
their respective versions.
We'll confirm if all licences for all instances are available and if each
server really has the number of instances mentioned in the support contract.

Thanks again,

Felipe

"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:...
> Felipe wrote:
>
>> I'm looking for a way to get the version of each SQL Server instances
>> installed locally on a server.
>> Does anybody know the best way of doing that?
>>

>
> I use a VBScript program. You would need a connection string for each
> instance.
> ===========
> ' Retrieve SQL Server version.
>
> Option Explicit
>
> Dim strConnect, adoConnection, adoRecordset, objShell
> Dim strVersion, strLevel, strEdition
>
> ' Construct connection string for PocketLunch database.
> strConnect = "DRIVER=SQL Server;" _
> & "Trusted_Connection=Yes;" _
> & "DATABASE=Master;" _
> & "SERVER=MyServer\MyInstance"
>
> ' Create ADO objects and connect to PocketLunch database.
> Set adoConnection = CreateObject("ADODB.Connection")
> adoConnection.ConnectionString = strConnect
> adoConnection.Open
>
> Set adoRecordset = CreateObject("ADODB.Recordset")
> Set adoRecordset.ActiveConnection = adoConnection
>
> ' Retrieve balances for each account as of specified date.
> adoRecordset.Source = "SELECT SERVERPROPERTY('productversion') AS Version,
> " _
> & "SERVERPROPERTY('productlevel') AS Level, " _
> & "SERVERPROPERTY('edition') AS Edition"
> adoRecordset.Open
>
> ' Enumerate account balances.
> Do Until adoRecordset.EOF
> strVersion = adoRecordset.Fields("Version").Value
> strLevel = adoRecordset.Fields("Level").Value
> strEdition = adoRecordset.Fields("Edition").Value
> Wscript.Echo "Version: " & strVersion
> Wscript.Echo "Level: " & strLevel
> Wscript.Echo "Edition: " & strEdition
> adoRecordset.MoveNext
> Loop
>
> ' Clean up.
> adoRecordset.Close
> adoConnection.Close
> ==========
> Otherwise, you can run the query (the Source property of the ADO Recordset
> object above) with a command line tool or GUI.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>



 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      09-18-2008
I looked for a way to enumerate all instances, but the only solution I found
used .NET. There must be an SQL query (when you connect to the default
instance) to do this, but I could not find it. One way would be to run "net
start" and parse everything that starts with MSSQL$ for instance names,
except under newer versions of SQL the service seems to be named:

SQL Server (<instance name>)

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Carlos Felipe França da Fonseca" <> wrote in
message news:...
> Thanks for your reply, Richard.
>
> I'm going to run this solution on many servers, locally and monthly using
> Tivoli monitoring. The reason of running that is for auditing purposes.
> The problem is that I don't know how many instances each server is
> running.
> So, we'll need to discover how many instances the server is running and
> also
> their respective versions.
> We'll confirm if all licences for all instances are available and if each
> server really has the number of instances mentioned in the support
> contract.
>
> Thanks again,
>
> Felipe
>
> "Richard Mueller [MVP]" <rlmueller-> wrote in
> message news:...
>> Felipe wrote:
>>
>>> I'm looking for a way to get the version of each SQL Server instances
>>> installed locally on a server.
>>> Does anybody know the best way of doing that?
>>>

>>
>> I use a VBScript program. You would need a connection string for each
>> instance.
>> ===========
>> ' Retrieve SQL Server version.
>>
>> Option Explicit
>>
>> Dim strConnect, adoConnection, adoRecordset, objShell
>> Dim strVersion, strLevel, strEdition
>>
>> ' Construct connection string for PocketLunch database.
>> strConnect = "DRIVER=SQL Server;" _
>> & "Trusted_Connection=Yes;" _
>> & "DATABASE=Master;" _
>> & "SERVER=MyServer\MyInstance"
>>
>> ' Create ADO objects and connect to PocketLunch database.
>> Set adoConnection = CreateObject("ADODB.Connection")
>> adoConnection.ConnectionString = strConnect
>> adoConnection.Open
>>
>> Set adoRecordset = CreateObject("ADODB.Recordset")
>> Set adoRecordset.ActiveConnection = adoConnection
>>
>> ' Retrieve balances for each account as of specified date.
>> adoRecordset.Source = "SELECT SERVERPROPERTY('productversion') AS
>> Version, " _
>> & "SERVERPROPERTY('productlevel') AS Level, " _
>> & "SERVERPROPERTY('edition') AS Edition"
>> adoRecordset.Open
>>
>> ' Enumerate account balances.
>> Do Until adoRecordset.EOF
>> strVersion = adoRecordset.Fields("Version").Value
>> strLevel = adoRecordset.Fields("Level").Value
>> strEdition = adoRecordset.Fields("Edition").Value
>> Wscript.Echo "Version: " & strVersion
>> Wscript.Echo "Level: " & strLevel
>> Wscript.Echo "Edition: " & strEdition
>> adoRecordset.MoveNext
>> Loop
>>
>> ' Clean up.
>> adoRecordset.Close
>> adoConnection.Close
>> ==========
>> Otherwise, you can run the query (the Source property of the ADO
>> Recordset object above) with a command line tool or GUI.
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>

>
>



 
Reply With Quote
 
Carlos Felipe França da Fonseca
Guest
Posts: n/a

 
      09-19-2008
I got it using registry keys:

strKeyPath = "SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL"

Set
objReg=GetObject("winmgmts:{impersonationLevel=imp ersonate}!\\.\root\default:StdRegProv")
objReg.EnumValues &H80000002, strKeyPath, arrEntryNames, arrValueTypes

For count=0 To UBound(arrEntryNames)
objReg.GetStringValue &H80000002, strKeyPath, arrEntryNames(count),
strInstance
objReg.GetStringValue &H80000002, "SOFTWARE\Microsoft\Microsoft SQL
Server\" & strInstance & "\Setup", "Version", strVersion
objReg.GetDWORDValue &H80000002, "SOFTWARE\Microsoft\Microsoft SQL
Server\" & strInstance & "\Setup", "SQLCluster", strIsClustered
If strIsClustered = 0 Then strIsClustered = "Stand-alone" Else
strIsClustered = "Clustered"
Wscript.Echo count+1 & ". " & arrEntryNames(count) & " - " & strVersion
& " - " & strIsClustered
Next

Thank you again for your efforts, Richard!

Regards,

Felipe

"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:...
>I looked for a way to enumerate all instances, but the only solution I
>found used .NET. There must be an SQL query (when you connect to the
>default instance) to do this, but I could not find it. One way would be to
>run "net start" and parse everything that starts with MSSQL$ for instance
>names, except under newer versions of SQL the service seems to be named:
>
> SQL Server (<instance name>)
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Carlos Felipe França da Fonseca" <> wrote in
> message news:...
>> Thanks for your reply, Richard.
>>
>> I'm going to run this solution on many servers, locally and monthly using
>> Tivoli monitoring. The reason of running that is for auditing purposes.
>> The problem is that I don't know how many instances each server is
>> running.
>> So, we'll need to discover how many instances the server is running and
>> also
>> their respective versions.
>> We'll confirm if all licences for all instances are available and if each
>> server really has the number of instances mentioned in the support
>> contract.
>>
>> Thanks again,
>>
>> Felipe
>>
>> "Richard Mueller [MVP]" <rlmueller-> wrote in
>> message news:...
>>> Felipe wrote:
>>>
>>>> I'm looking for a way to get the version of each SQL Server instances
>>>> installed locally on a server.
>>>> Does anybody know the best way of doing that?
>>>>
>>>
>>> I use a VBScript program. You would need a connection string for each
>>> instance.
>>> ===========
>>> ' Retrieve SQL Server version.
>>>
>>> Option Explicit
>>>
>>> Dim strConnect, adoConnection, adoRecordset, objShell
>>> Dim strVersion, strLevel, strEdition
>>>
>>> ' Construct connection string for PocketLunch database.
>>> strConnect = "DRIVER=SQL Server;" _
>>> & "Trusted_Connection=Yes;" _
>>> & "DATABASE=Master;" _
>>> & "SERVER=MyServer\MyInstance"
>>>
>>> ' Create ADO objects and connect to PocketLunch database.
>>> Set adoConnection = CreateObject("ADODB.Connection")
>>> adoConnection.ConnectionString = strConnect
>>> adoConnection.Open
>>>
>>> Set adoRecordset = CreateObject("ADODB.Recordset")
>>> Set adoRecordset.ActiveConnection = adoConnection
>>>
>>> ' Retrieve balances for each account as of specified date.
>>> adoRecordset.Source = "SELECT SERVERPROPERTY('productversion') AS
>>> Version, " _
>>> & "SERVERPROPERTY('productlevel') AS Level, " _
>>> & "SERVERPROPERTY('edition') AS Edition"
>>> adoRecordset.Open
>>>
>>> ' Enumerate account balances.
>>> Do Until adoRecordset.EOF
>>> strVersion = adoRecordset.Fields("Version").Value
>>> strLevel = adoRecordset.Fields("Level").Value
>>> strEdition = adoRecordset.Fields("Edition").Value
>>> Wscript.Echo "Version: " & strVersion
>>> Wscript.Echo "Level: " & strLevel
>>> Wscript.Echo "Edition: " & strEdition
>>> adoRecordset.MoveNext
>>> Loop
>>>
>>> ' Clean up.
>>> adoRecordset.Close
>>> adoConnection.Close
>>> ==========
>>> Otherwise, you can run the query (the Source property of the ADO
>>> Recordset object above) with a command line tool or GUI.
>>>
>>> --
>>> Richard Mueller
>>> MVP Directory Services
>>> Hilltop Lab - http://www.rlmueller.net
>>> --
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Guidance on how to access WMI instance members within an instance! nutrageous_1@yahoo.com Windows Vista Drivers 3 07-15-2010 09:06 AM
Cannot Register SQL Server Instance Mike Windows Small Business Server 2 06-30-2006 12:47 PM
How to Tell what version os Windows Server 2003 is installed Mike Hunt Windows Small Business Server 3 06-20-2006 05:29 AM
Windows Server Update Services RTM Setup fails on SQL Server 2000 SP4 Second instance Andrea Borghi Update Services 2 06-12-2005 01:32 AM
SBS Monitoring installed on Full version Server 2003 Eric_Hartley Windows Small Business Server 2 03-16-2005 05:27 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59