Last active
October 24, 2018 14:51
-
-
Save joe-scalise/2e8b6909c684a4f438c7f096d66b75d2 to your computer and use it in GitHub Desktop.
Windows Scheduled Task, with Managed Service Account, Runs Every 15 Minutes, Indefinitely.
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
| $appPath = "testapp.exe" | |
| # for testing with user account instead of MSA | |
| $serviceAccount = whoami.exe | |
| #serviceAccount = "DOMAIN\MyServiceAccount" | |
| $taskName = "My Test Task" | |
| $command = "-Command "". 'C:\apps\$appPath'""" | |
| $action = New-ScheduledTaskAction -Execute $command | |
| $execute = Get-Date -Hour 0 -Minute 0 -Second 0 -Millisecond 0 | |
| $trigger = New-ScheduledTaskTrigger -Once -at $execute | |
| # for testing with local account instead of MSA | |
| $principal = New-ScheduledTaskPrincipal -UserID $serviceAccount | |
| #$principal = New-ScheduledTaskPrincipal -UserID $serviceAccount -LogonType Password | |
| $task = Register-ScheduledTask $taskName -Action $action -trigger $trigger -Principal $principal | |
| $task.Triggers.Repetition.Interval = "PT15M" | |
| $task.Triggers.Repetition.Duration = "" | |
| $task | Set-ScheduledTask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment