Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Created September 9, 2019 12:26
Show Gist options
  • Save johnmmoss/efc14b6ea851fb8c3b98643d53204e1e to your computer and use it in GitHub Desktop.
Save johnmmoss/efc14b6ea851fb8c3b98643d53204e1e to your computer and use it in GitHub Desktop.
Example script to install a scheduled task for a console application
Param(
$userAccount = "NT AUTHORITY\SYSTEM",
$exePath = "C:\Code\SampleTaskConsole\bin\Debug\SampleTaskConsole.exe",
$taskName = "ScormCloudReporting"
)
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
$action = New-ScheduledTaskAction -Execute $exePath
$trigger = New-ScheduledTaskTrigger -Daily -At 1am
$principal = New-ScheduledTaskPrincipal -UserID $userAccount -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskName -Description $taskName -Principal $principal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment