Background:
I have a Test Server (SQL Server 2008 R2) that contains a DB in which I store information about other DBs from my Production Servers (Mix of SQL Server 2008 R2 and 2012). I have multiple scripts that I run monthly which collects information, such as number of VLFs, from each DB on a server. What I have been doing is running the scripts on each of my Production Servers, copying the results into a .txt file, and importing the .txt file into the DB on my Test Server.
Problem:
How can automate my scripts to run on every Production server without me logging on to each Production Server and running each script?
How can I insert the collected information into my Test Server DB without having to copy/paste?
Sample Script:
SET NOCOUNT ON;
CREATE TABLE #to
(
ServerName varchar(20),
CaptureDate DATETIME,
DBName SYSNAME,
FileCount INT
);
DECLARE @v INT;
SELECT @v = CONVERT(INT, PARSENAME(CONVERT(VARCHAR(32),
SERVERPROPERTY('ProductVersion')), 4));
DECLARE @sql NVARCHAR(MAX);
SET @sql = N'CREATE TABLE #ti
(
' + CASE WHEN @v >= 11 THEN 'RecoveryUnitId INT,' ELSE '' END + '
FileId int
, FileSize nvarchar(255)
, StartOffset nvarchar(255)
, FSeqNo nvarchar(255)
, Status int
, Parity int
, CreateLSN nvarchar(255)
);';
SELECT @sql = @sql + '
INSERT #ti EXEC ' + QUOTENAME(name)
+ '.sys.sp_executesql N''DBCC LOGINFO WITH NO_INFOMSGS'';
INSERT INTO
#to(DBName, FileCount) SELECT ''' + name + ''', COUNT(*) FROM #ti;
TRUNCATE TABLE #ti;'
FROM sys.databases;
EXEC sp_executesql @sql;
SELECT @@ServerName,GETDATE(),DBName,FileCount
FROM #to
ORDER BY DBName
DROP TABLE #to;
Any help would be greatly appreciated.