Skip to content

Instantly share code, notes, and snippets.

@joe-scalise
Last active October 24, 2018 14:51
Show Gist options
  • Select an option

  • Save joe-scalise/2e8b6909c684a4f438c7f096d66b75d2 to your computer and use it in GitHub Desktop.

Select an option

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.
$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