Skip to content

Instantly share code, notes, and snippets.

@vexx32
Created July 13, 2018 14:07
Show Gist options
  • Save vexx32/09ab9e6d24073aa1d5517c8734a79a85 to your computer and use it in GitHub Desktop.
Save vexx32/09ab9e6d24073aa1d5517c8734a79a85 to your computer and use it in GitHub Desktop.
$TriggerParams = @{
Daily = $true
At = '12am'
ErrorAction = 'Stop'
}
$SettingsParams = @{
ExecutionTimeLimit = [TimeSpan]::FromHours(2)
ErrorAction = 'Stop'
}
$TaskParams = @{
Action = $Action
Trigger = New-ScheduledTaskTrigger @TriggerParams
Settings = New-ScheduledTaskSettingsSet @SettingsParams
ErorAction = 'Stop'
}
$Task = New-ScheduledTask @TaskParams
$RegisterParams = @{
TaskName = $TaskName
InputObject = $Task
User = $SchedTaskCredUser
Password = $SchedTaskCredPwd
ErrorAction = 'Stop'
}
Register-ScheduledTask @RegisterParams
$Task = Get-ScheduledTask -TaskName $TaskName
$Task.Triggers.Repetition.Duration = "P1D"
$Task.Triggers.Repetition.Interval = "PT2M"
$Task | Set-ScheduledTask -User $SchedTaskCredUser -Password $SchedTaskCredPwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment