Last active
June 6, 2017 13:06
-
-
Save WimObiwan/afd672528ef5c159a40be7fe0440129c to your computer and use it in GitHub Desktop.
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
#$hourlyStartTimes = @('08:00','09:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00') | |
$hourlyStartTimes = @(for ($i = 8; $i -le 19; $i++) { "$($i):00" } ) | |
$hourlyTriggers = @($hourlyStartTimes | %{ New-JobTrigger -Daily -At $_ -RandomDelay '1:00' }) | |
$nightlyTrigger = New-JobTrigger -Daily -At '0:00' -RandomDelay '4:00' | |
Register-ScheduledJob -Name 'Backup GIT Incremental' -Trigger $hourlyTriggers -ScriptBlock { C:\SourceGIT\backup.ps1 -LastDays 5 } | |
Register-ScheduledJob -Name 'Backup GIT' -Trigger $nightlyTrigger -ScriptBlock { C:\SourceGIT\backup.ps1 } | |
#Troubleshooting: | |
# List ScheduledJobs: | |
Get-ScheduledJob | |
# List Job executions: | |
Get-Job | Format-Table -AutoSize | |
Get-Job | select Id, Name, PSJobTypeName, State, HasMoreData, Location, Command, @{Name='PSBeginTime'; Expression={$_.PSBeginTime}}, @{Name='PSEndTime'; Expression={$_.PSEndTime}} | Format-Table -AutoSize | |
# Show Job errors & output | |
Receive-Job -Id xxx | |
# Force run 1 scheduled job: | |
(Get-ScheduledJob -Id xxx).Run() | |
# Force run all schedules jobs: | |
(Get-ScheduledJob).Run() | |
# Set credentials | |
$cred = Get-Credential | |
Get-ScheduledJob 2 | Set-ScheduledJob -Credential $cred | |
# Job is visible under Windows Scheduled tasks: | |
# -> Task Scheduler | |
# -> Task Scheduler Library | |
# -> Microsoft | |
# -> Windows | |
# -> PowerShell | |
# -> ScheduledJobs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment