Created
June 26, 2014 09:24
-
-
Save chrismckelt/dec703509eec3f49beae to your computer and use it in GitHub Desktop.
PowerShell - Schedule Task via Windows Scheduler
This file contains 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
$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