Skip to content

Instantly share code, notes, and snippets.

@chrismckelt
Created June 26, 2014 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismckelt/dec703509eec3f49beae to your computer and use it in GitHub Desktop.
Save chrismckelt/dec703509eec3f49beae to your computer and use it in GitHub Desktop.
PowerShell - Schedule Task via Windows Scheduler
$Until = New-TimeSpan -End "2036-01-01"
$User = "SYSTEM"
$Path = Resolve-Path MyCustom.Tasks.exe
Function ScheduleTask($name, $task, $time)
{
$Trigger = New-ScheduledTaskTrigger -Once -At $time -RepetitionInterval (New-TimeSpan -Days 1) -RepetitionDuration $Until
$Action = New-ScheduledTaskAction –Execute $Path -Argument $task
try {
Write-Host "Removing Task Schedule"
Unregister-ScheduledTask -TaskName $name -Confirm:$false
}
catch {
}
Write-Host "Adding Task Schedule"
Register-ScheduledTask -TaskName $name -Trigger $Trigger -User $User –Action $Action
}
ScheduleTask "Sample task - Calculate All Summaries" "BulkCalculateTask" "3am"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment