user4317867
user4317867

Reputation: 2448

Enable task to be deleted after X time

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

Answers (1)

Rahul
Rahul

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

Related Questions