Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding editions across domains

Status
Not open for further replies.

JaybeeinTekTips

Technical User
Nov 5, 2004
20
GB
Hi all,

I've got a script that I want to alter, so it retrieves servername and edition faithfully from each SQL Server. This retrieves servernames, but only gives me the edition of the local server. Anyone know how to adjust?

Thanks,

Jaybee.


-- Show sql servers in a domain
--
-- *****************************************************************
-- ************ Run from a text-ommitted server due to reverse trusts ***
-- *****************************************************************
--
SET NOCOUNT ON
DECLARE @string varchar(128)
IF EXISTS(SELECT * FROM TEMPDB..SYSOBJECTS WHERE NAME LIKE '#t_%') DROP TABLE #t
create table #t ( ServerName varchar(128) )

DECLARE @Match varchar(128)
DECLARE @NotMatch1 varchar(128)
DECLARE @NotMatch2 varchar(128)

SET @Match = ' %'
SET @Notmatch1 = '%(local)%'
-- SET @Notmatch2 = '%.......%'
SET @Notmatch2 = '%UKD%-%'

SET @string = 'OSQL -E -S Server1 -Q ' + '"' + 'EXEC MASTER..XP_CMDSHELL ' + '''' + 'OSQL -L' + '''' + '"' ; INSERT INTO #t EXEC xp_cmdshell @string
SET @string = 'OSQL -E -S Server2 -Q ' + '"' + 'EXEC MASTER..XP_CMDSHELL ' + '''' + 'OSQL -L' + '''' + '"' ; INSERT INTO #t EXEC xp_cmdshell @string
SET @string = 'OSQL -E -S Server3 -Q ' + '"' + 'EXEC MASTER..XP_CMDSHELL ' + '''' + 'OSQL -L' + '''' + '"' ; INSERT INTO #t EXEC xp_cmdshell @string


*/

SET NOCOUNT OFF

select RTRIM(LTRIM(ServerName)) ServerName from #t where ServerName like @Match and
ServerName not like @NotMatch1 and
ServerName not like @NotMatch2 group by ServerName order by ServerName

--select 'INSERT INTO #U VALUES ( ''' + RTRIM(LTRIM(ServerName)) + ''')' ServerName from #t where ServerName like @Match and
-- ServerName not like @NotMatch1 and
-- ServerName not like @NotMatch2 group by ServerName order by ServerName

drop table #t

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top