Reputation: 2448
How can I enable a task created using PowerShell's Register-ScheduledTask
to be deleted If the task is not scheduled to run again? As in New-JobTrigger -Once -At $ScheduledTime
The option is seen in the Task Scheduler GUI > Task Properties > Settings tab > The last checkbox option reads:
If the task is not scheduled to run again, delete it after: <time period>
MS TechNet article Searching for enabling this option using PowerShell does not turn up any relevant results, mostly how to enable tasks and so on.
Upvotes: 0
Views: 2869
Reputation: 77846
You should use a New-ScheduledTaskSettingsSet
like
New-ScheduledTaskSettingsSet -DeleteExpiredTaskAfter <TimeSpan>
$STSet = New-ScheduledTaskSettingsSet -DeleteExpiredTaskAfter <TimeSpan>
Register-ScheduledTask mytask -Action <actionobject> -Settings $STSet
Upvotes: 2