Windows – How to Edit Conditions of a Scheduled Task via CMD

scheduled-taskwindows

I know you can create and edit the actions and triggers of a scheduled task via CMD, but when I open the created task in Task Scheduler all of the Conditions are set to their default configurations. I've tried looking them up in the microsoft documentation but all I've been able to find are the switches /options for the actions and triggers portion of the scheduled task.

I'd like to be able to do this via Command line so that I can deploy this scheduled task to all of our Windows 10 workstations with PDQ deploy.

For reference, here is the command I am currently working with

'schtasks /create /tn SeatSaver /tr "taskkill /F /IM Executable.EXE" /sc 
ONIDLE /i 60 /ru domain\username /rp password' 

according to the documentation this command should create a task that kills a certain program after 60 minutes of the Workstation being idle. But when I open up the created task and look at the conditions, the options for conditions are all at their default settings, which to me means that the command won't work as is, because the default setting for idling is to not care if the PC is idle, which I don't want.

Is there anyway to make this work via CMD?

Edit: I've read through Microsoft's Powershell Documentation for this, but I wasn't able to find anything regarding the "OnIdle" trigger, or if it even exists. Does anyone have a list of Triggers for setting up scheduled tasks with Powershell?

https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtask?view=win10-ps#optional-parameters

https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtasktrigger?view=win10-ps

Best Answer

The New-ScheduledTask command has a settings parameter that accepts a settings object, which can be created using New-ScheduledTaskSettingsSet and that has a -RunOnlyIfIdle parameter.

This implies that 'on idle' is not a trigger in itself, but a limiting control on the trigger that stops the task running if the host is not idle.

Perhaps in CMD you also require a periodic schedule to get your ONIDLE, such as by using the /MO and /ST parameters.