One email each morning lists every SQL Agent job due to run that day, in time order. For each job it shows the time, server, job and category, how often it repeats, how long it usually takes (the average of the last 30 days of successful runs), roughly when it ends, and how its last run went, with failures in red. A log backup every 15 minutes is one row, not ninety-six. It is the quickest way to see what runs overnight, which jobs overlap, and what failed last time.
There are two versions, and both send the same email. Use the stored procedure where only T-SQL and Database Mail are allowed. Use the PowerShell script where the audit runner already runs.
- dbo.usp_SendJobTimetable (sql\JobTimetable.sql): run by a SQL Agent job, sent by Database Mail. Reads other servers through linked servers. Its servers and job patterns are kept in the table dbo.JobTimetableSource.
- Send-JobTimetable.ps1: run by a scheduled task or the audit runner. Connects to each server directly. Its servers and patterns are parameters.
Schedules follow SQL Agent’s own rules: daily, weekly and monthly, “first Tuesday” and “last weekday”, start and end dates, and repeats during the day. Jobs that run when SQL Server Agent starts or when the CPU is idle are listed separately, because they have no set time. A server that can’t be read is named at the top of the email, and the rest are still reported.
Step 1: Check Database Mail
The procedure sends through a Database Mail profile, DBA by default. Database Mail XPs must be on (see Database Mail Setup and Troubleshooting).
SELECT name, value_in_use FROM sys.configurations WHERE name = N'Database Mail XPs';
EXEC msdb.dbo.sysmail_help_profile_sp;
Step 2: Create the procedure
Run sql\JobTimetable.sql on the server that will send the email. It creates the DBA database if it is missing, dbo.JobTimetableSource with one row (every job on this server), and dbo.usp_SendJobTimetable. It is safe to run again. Use -I with sqlcmd: the procedure needs QUOTED_IDENTIFIER on.
sqlcmd -S SQLPROD01 -E -I -i "C:\DBA\sql\JobTimetable.sql"
Step 3: Add jobs from other servers
Make a linked server for each other server, mapped to the caller’s own Windows login so no password is stored, and give the SQL Server Agent service account SQLAgentReaderRole in msdb on that server. Then add one row per server and job name pattern (LIKE patterns, % and _). LinkedServer NULL means this server. Set IsEnabled = 0 to leave a row out for a while.
EXEC master.dbo.sp_addlinkedserver @server = N'SQLPROD02', @srvproduct = N'SQL Server';
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname = N'SQLPROD02', @useself = N'TRUE';
USE DBA;
INSERT dbo.JobTimetableSource (LinkedServer, JobNamePattern, Note)
VALUES (N'SQLPROD02', N'%Backup%', N'Backups on PROD02'),
(N'SQLPROD02', N'%CHECKDB%', N'Integrity checks on PROD02'),
(N'SQLPROD03', N'%', N'Everything on PROD03');
Step 4: Test it without sending
With no recipients, the procedure returns the subject and the HTML instead of sending. @DayOffset = 1 shows tomorrow.
USE DBA;
EXEC dbo.usp_SendJobTimetable; -- today, not sent
EXEC dbo.usp_SendJobTimetable @DayOffset = 1; -- tomorrow, not sent
EXEC dbo.usp_SendJobTimetable @Recipients = N'[email protected]';
Step 5: Schedule it
Set the recipients, profile, run time and failure operator at the top of sql\JobTimetable_AgentJob.sql, then run it. It creates the job “DBA – Email SQL Agent job timetable”, daily at 06:00 by default. If the job already exists it is left alone; delete it first to recreate it.
EXEC msdb.dbo.sp_start_job @job_name = N'DBA - Email SQL Agent job timetable';
The PowerShell version
Send-JobTimetable.ps1 reads msdb on each server, so the account needs SQLAgentReaderRole in msdb there. -AlsoInclude takes one entry per server: the name alone for every enabled job, or the name, a colon and patterns separated by ; (PowerShell -like, * and ?). It sends by Database Mail on -MailServer (the account needs DatabaseMailUserRole in msdb) or through an internal SMTP relay that needs no login. With no -MailTo it only saves the HTML to -OutFile.
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\DBA\Send-JobTimetable.ps1" -Server SQLPROD01 -AlsoInclude "SQLPROD02:*Backup*;*CHECKDB*,SQLPROD03" -MailTo "[email protected]"
It is also a task in DbaAudits.config.json, disabled until the servers and recipients are filled in. The runner runs at night, so that task uses DayOffset 1 and sends tomorrow’s timetable. To send it in the morning instead, schedule the script on its own and leave the task disabled.
Reading the timetable
- A red last result: the job failed last time. Check it before its next run (see Failed SQL Agent Job Triage).
- Long jobs whose end time runs past the start of another heavy job on the same server: backups, CHECKDB and index maintenance overlapping is the usual cause of a slow night.
- Anything still running into the working day.
- A server named at the top as unreadable: fix the linked server or permissions, or that server’s jobs are missing from the email.
From my SQL Server DBA handbook.