Tuesday 16 November 2010

How to remotely list scheduled tasks

I had the need of getting all details of the scheduled tasks of our servers, I could use a lot of other complex ways, but I still prefer simplicity of batch:
1. Create a file with the hostnames of all the computers you need to check for the
scheduled tasks (tasks.txt):
hostname1
hostname2
hostnameX

2. Create a batch file with (tasks.bat):
del out.csv
echo "HostName","TaskName","Next Run Time","Status","Logon Mode","Last Run Time","Last Result","Author","Task To Run","Start In","Comment","Scheduled Task State","Idle Time","Power Management","Run As User","Delete Task If Not Rescheduled","Stop Task If Runs X Hours and X Mins","Schedule","Schedule Type","Start Time","Start Date","End Date","Days","Months","Repeat: Every","Repeat: Until: Time","Repeat: Until: Duration","Repeat: Stop If Still Running">> out.csv
FOR /F %%a in (tasks.txt) Do schtasks.exe /query /fo csv /s %%a /v | FIND "%%a" >> out.csv

3. Run the batch file with a user that have admin rights on the server, you will get a CSV that can be easily imported on Excel or a similar application.

No comments:

Post a Comment