Created
October 14, 2017 19:10
-
-
Save gregjhogan/9c472f495be2d8316e3bc5c6bbdab33c to your computer and use it in GitHub Desktop.
Windows scheduled task that stays running forever and restarts if it dies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $folder = "C:\folder" | |
| $cmd = "powershell.exe " | |
| $args = "-NoLogo -NonInteractive -WindowStyle Maximized -File script.ps1" | |
| $user = "username-to-run-as" | |
| $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes 1) | |
| $action = New-ScheduledTaskAction -WorkingDirectory $folder -Execute $cmd -Argument $args | |
| $settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -MultipleInstances IgnoreNew -RestartInterval (New-TimeSpan -Minutes 1) -RestartCount 999 -ExecutionTimeLimit (New-TimeSpan -Seconds 0) | |
| $principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive | |
| $task = New-ScheduledTask -Principal $principal -Action $action -Settings $settings -Trigger $trigger | |
| Register-ScheduledTask -TaskName Selenium -InputObject $task -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment