[ How can i disable task scheduler jobs using powershell script ]
i'am looking for a powershell script that can be run to disable Task Scheduler job(internally disabling a .bat file) which can disable between the timestamps that we mention to the script. Is it doable using a Powershell script?
Any help appreciated!!
Answer 1
I would start off by using the handy-dandy SCHTASKS executable with CSV format output to get an object back with all your scheduled task information:
$tasks = & SCHTASKS /Query /V /FO CSV | ConvertFrom-Csv
The magic decoder ring of parameters: /Query is the operation, /V is verbose output, /FO CSV is the output format. Now that it is in an object, you can easily filter to find the task(s) you are looking for:
$task = $tasks | ? { $_.TaskName -eq "My Batch File" }
Which then makes it easy to enable or disable a task, again using the SCHTASKS executable:
& SCHTASKS /Change /DISABLE /TN "$Task.TaskName"
You can easily enable the task again with the same code, just replacing the /DISABLE with /ENABLE. SCHKTASKS is a very powerful tool to use for creating and manipulating scheduled tasks.
Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357.aspx
Answer 2
With Windows Server 2008 & newer, you can use SCHTASKS
or the COM object Schedule.Service
to manipulate tasks in a more object-oriented way. See http://letitknow.wordpress.com/2011/05/20/create-scheduled-task-by-using-powershell/ for a examples of using both SCHTASKS
and Schedule.Service
. Task Scheduler's COM interface is documented at http://msdn.microsoft.com/en-us/library/aa383608(v=vs.85)
Answer 3
only Windows 2012 / 8.1 and above https://technet.microsoft.com/en-us/library/jj649816%28v=wps.630%29.aspx