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!

Query Scheduled Jobs

Status
Not open for further replies.

k3lvin

Technical User
Jan 13, 2008
143
GB
I would like a script that will output all Windows Scheduled tasks and SQL Server Scheduled Jobs. I have managed to find a good way to query servers for Scheduled tasks using this batch script: schtasks /query /s hostname /fo CSV /NH > "c:\tasks.csv"

What I would like is a way to add the SQL scheduled jobs into the same csv. Is this possible? Thanks
 
Hello,
Here is a bit of code I use:
Code:
-- List enabled Job and step
SELECT 
     Jobs.enabled           AS Enabled 
    , Jobs.[name]           AS Job_Name 
    , Steps.step_id         AS Step_Num 
    , Steps.command 
    , Steps.step_name       AS Step_Name 
    , Schedules.next_run_date 
    , RIGHT('000000' + CAST (Schedules.next_run_time AS VARCHAR), 6) AS next_run_time 
    , SysSchedules.[name]   AS Sch_Name 
    , SysSchedules.[enabled] AS Sch_Enabled     
FROM  msdb.dbo.sysjobs Jobs 
RIGHT OUTER JOIN msdb.dbo.sysjobschedules Schedules 
    ON Jobs.Job_ID = Schedules.Job_ID
LEFT OUTER JOIN msdb.dbo.sysjobsteps Steps 
    ON Schedules.Job_ID = Steps.Job_ID 
INNER JOIN msdb.dbo.sysschedules SysSchedules 
ON Schedules.schedule_id = SysSchedules.schedule_id
WHERE Jobs.enabled = 1 
ORDER BY Job_Name, Sch_Name, Step_Num
As to combining the two, I have not tried to automate that.

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top