JSI Tip 9101. How can I generate a CSV file of all the scheduled job in my domain?

Jerold Schulman

February 28, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Using Schtasks.exe and NetViewC.bat, I have scripted ScheduleCSV.bat to generate a CSV (Coma Separated Value) file containing all the scheduled jobs on all of the computers in a domain.

NOTE: Tip 4806 Windows XP contains a full featured command-line scheduler.

NOTE: Tip 5335 Can I use the Windows XP command line scheduler in Windows 2000?

The each line in the CSV file contains the following information about a scheduled job:

"HostName""TaskName""Next Run Time""Status""Last Run Time""Last Result""Creator""Schedule""Task To Run""Start In""Comment""Scheduled Task State""Scheduled Type""Start Time""Start Date""End Date""Days""Months""Run As User""Delete Task If Not Rescheduled""Stop Task If Runs X Hours and X Mins""Repeat: Every""Repeat: Until: Time""Repeat: Until: Duration""Repeat: Stop If Still Running""Idle Time""Power Management"

The syntax for using ScheduleCSV.bat is:

ScheduleCSV CSVFile NetBIOS_DOMAIN USER_SAMID PASSWORD

Where:

CSVFile         is the fully qualified CSV file path.NetBIOS_DOMAIN  is the NetBIOS domain name, like JSIINC.USER_SAMID      is the User Logon ID, like Jerry, of a domain administrator account.PASSWORD        is the password of the USER_SAMID account.

ScheduleCSV.bat contains:

@echo offif {%4}=={} @echo Syntax: ScheduleCSV CSVFile NetBIOS_DOMAIN USER_SAMID PASSWORD&goto :EOFsetlocal ENABLEDELAYEDEXPANSIONset out="%TEMP%ScheduleCSV_%RANDOM%.TMP"set csvfile=%1set dom=%2set user=%3set pwd=%4set work=%dom%%user%set user="%work:"=%"set Head=Nif exist %csvfile% del /q %csvfile%for /f "Tokens=*" %%c in ('netviewc %dom%') do ( if "!Head!" EQU "Y" schtasks /query /S "%%c" /U %user% /P %pwd% /FO CSV /NH /V>>%out% if "!Head!" EQU "N" set Head=Y&schtasks /query /S "%%c" /U %user% /P %pwd% /FO CSV /V>%out%)for /f "Tokens=*" %%a in ('type %out%') do ( @echo %%a>>%csvfile%)del /q %out%endlocal



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like