This is what I've gathered so far. I need a scheduled task that runs only 1 time, at the next startup (whenever that is) and after it runs it should delete itself.
Register-ScheduledTask -TaskName "Test 1" -InputObject (
(
New-ScheduledTask -Action (
New-ScheduledTaskAction -Execute "PowerShell.exe"
) -Trigger (
New-ScheduledTaskTrigger -Once -AtStartup # both of these can't be used
) -Settings (
New-ScheduledTaskSettingsSet -DeleteExpiredTaskAfter 00:00:01
)
) | ForEach-Object { $_.Triggers[0].EndBoundary = <# 1 second after task is run #> ; $_ }
)
I'm not sure if it's possible, if it's not, please let me know so I can explore other options, but if it is, I need help figuring out how I can make it happen. The EndBoundary
looks like it needs a date but I don't have any to give it, because it's unknown when the next Startup is.
I'm doing this because I need to run a PowerShell code at the next startup (time unknown) and only 1 time.