JaybeeinTekTips
Technical User
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
--
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
--