Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Remote SQL Version Query Problem Expand / Collapse
Author
Message
Posted Wednesday, April 16, 2008 3:58 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 26, 2014 12:41 AM
Points: 84, Visits: 64
I had a recent problem where at no notice I had to query about 100 SQL server instances to get the Version, patch level and edition prior to an audit.

I used the following command:

select serverproperty('productversion'), serverproperty('productlevel'), serverproperty('edition')

I found myself wondering if this command could be used remotely instead of locally? If it can what modifications would have to be made to enable that to happen?

My ultimate goal was to be able to output a single table with SERVER NAME, PRODUCT VERSION, PRODUCT LEVEL, EDITION for all 100 servers by executing a variation of the above query on one server only.

Any thoughts anyone?


AMO AMAS AMATIT AGAIN
Post #485512
Posted Wednesday, April 16, 2008 4:10 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 4:43 AM
Points: 870, Visits: 897
Hi David,

if you had linked servers setup you could run the following command:

exec a_linked_server.master.dbo.sp_executesql N'select serverproperty(''productversion''), serverproperty(''productlevel''), serverproperty(''edition'')'

If you don't have permanent linked servers set up you could potentially create the linked servers on the fly if you had a table with the name of all your servers. Just go through that table and use sp_addlinkedserver and sp_addlinkedsrvlogin to create the linked server and associated logins. You'd then use sp_dropserver to remove the linked server.


Karl
source control for SQL Server
Post #485523
Posted Wednesday, April 16, 2008 4:17 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 27, 2014 3:44 AM
Points: 179, Visits: 331
Use SQLCMD for this....
In MS Management Stusio(SSMS), you will find SQLCMD Mode under the Query menu....

Use the following script -

:setvar defaultserver
:connect $(defaultserver)
USE [master]
GO
select serverproperty('productversion'),
serverproperty('productlevel'),
serverproperty('edition')

Just change the server name and execute.....hope this helps!

Note: The windows login needs to have administrative privileges on all the servers......also if you have multiple instances use ....for example SON1843\sql


Chandrachurh Ghosh
DBA – MS SQL Server
Ericsson India Global Services Limited
Quality is not an act, it is a habit.
Post #485530
Posted Wednesday, April 16, 2008 5:19 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 26, 2014 12:41 AM
Points: 84, Visits: 64
Excellent! Thanks for the prompt (and useful) replies. I went with option 2 and used the SQLCMD which has worked a treat.

Is it possible to loop SQLCMD so that the defaultserver variable could be updated each time from a table of server names?


AMO AMAS AMATIT AGAIN
Post #485555
Posted Wednesday, April 16, 2008 6:09 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 27, 2014 3:44 AM
Points: 179, Visits: 331
I am devising a way to help you out in looping, as I know the tidious job in doing recursive work for a volume as big as 100 servers.....
As of now, the following process will let you save your outputs to a centrally located excel file. This will do away with the copy and paste stuff each time you run the script for a server.

First of all share a folder and create a blank excel workbook with a worksheet named Result. Name the columns SERVER, PRODUCTVERSION, PRODUCTLEVEL, EDITION in the worksheet.

That's all....
as before run the following script for each of the servers you want to drill in...changing just the servername SON1286
:setvar defaultserver SON1286
:connect $(defaultserver)
USE [master]
GO

IF NOT EXISTS (SELECT srv.name
FROM sys.servers srv
WHERE srv.server_id != 0
AND srv.name = N'ExcelSource')
EXEC sp_addlinkedserver 'ExcelSource',
'Jet 4.0',
'Microsoft.Jet.OLEDB.4.0',
'\\son1286\Share\Test.xls',
NULL,
'Excel 5.0'

DECLARE @TSQLSTMT VARCHAR(4000),
@SERVER VARCHAR(100),
@PRODUCTVERSION VARCHAR(150),
@PRODUCTLEVEL VARCHAR(150),
@EDITION VARCHAR(150)
SELECT @SERVER=CONVERT(VARCHAR,@@SERVERNAME),
@PRODUCTVERSION=CONVERT(VARCHAR,SERVERPROPERTY('PRODUCTVERSION')),
@PRODUCTLEVEL=CONVERT(VARCHAR,SERVERPROPERTY('PRODUCTLEVEL')),
@EDITION=CONVERT(VARCHAR,SERVERPROPERTY('EDITION'))
SET @TSQLSTMT = 'Insert ExcelSource...[Result$]
(SERVER,
PRODUCTVERSION,
PRODUCTLEVEL,
EDITION
)
SELECT '''+@SERVER+''',
'''+@PRODUCTVERSION+''',
'''+@PRODUCTLEVEL+''',
'''+@EDITION+''''
EXEC(@TSQLSTMT)

Note: You must not have any linked server already on your servers named ExcelSource. You can choose a unique name if required.


Chandrachurh Ghosh
DBA – MS SQL Server
Ericsson India Global Services Limited
Quality is not an act, it is a habit.
Post #485581
Posted Wednesday, April 16, 2008 6:19 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 10, 2010 5:07 AM
Points: 2,732, Visits: 23,078
Download an eval version of SQL 2008. You can actually do this in management studio.
Post #485592
Posted Wednesday, April 16, 2008 9:39 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, August 28, 2009 2:09 AM
Points: 112, Visits: 196
the SQLCMD utility can discover all the SQLserver instances [that haven't chosen to be hidden]

so here are some horrible hacks for you ...

HACK 1 (bad!)
at the command prompt (ie start run cmd) do
sqlcmd -Lc
and then use Notepad to edit each line to become (2 wrapped lines shown here)
SQLCMD -S svr1-E -Q "select serverproperty('productversion'), serverproperty('productlevel'), serverproperty('edition')"
SQLCMD -S svr2\SQL2005 -E -Q "select serverproperty('productversion'), serverproperty('productlevel'), serverproperty('edition')"


HACK 2 (worse!)
create table #SVRS(instname nvarchar(128))
insert into #SVRS
exec master..xp_cmdshell 'SQLCMD -Lc'
select CMD='SQLCMD -S '+instname+' -E -Q "select serverproperty(''productversion''), serverproperty(''productlevel''), serverproperty(''edition'')"'
from #SVRS
order by 1

drop table #SVRS

and of course you can dream up even nastier cursor-driven examples
- but handy to massage into a relational table for subsequent querying

yuck!
Dick
Post #485770
Posted Thursday, June 19, 2008 7:49 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, August 6, 2014 4:37 AM
Points: 520, Visits: 1,677
Afternoon
Is there any way of returning the query
exec a_linked_server.master.dbo.sp_executesql N'select serverproperty(''productversion'')
to a local variable ?
we do not have MSDTC enabled on the target servers so an 'insert into' on a temporary table won't work
Post #519865
Posted Thursday, June 19, 2008 7:58 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, August 28, 2009 2:09 AM
Points: 112, Visits: 196
moderately clunky, but this might do
declare @remver sql_variant
select @remver=REMVER from OPENQUERY(a_linked_server,'select REMVER=serverproperty(''productversion'')')
select @remver

although many better ways with SMO, ADO.NET etc

HTH
Dick
Post #519874
Posted Friday, June 20, 2008 12:27 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, August 6, 2014 4:37 AM
Points: 520, Visits: 1,677
Morning
Clunky or not - does the job.
Thanks for your help - I wasted a day trying to get this to work
Much appreciated.
Post #520366
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse