Creating a Scheduled Job to Execute a Powershell Script
This article has not been completed yet. However, it may already contain helpful information and therefore it has been published at this stage.
# Define the interval to repeat the job
# Example 1 (daily at 09:00 AM without any limit)
# Var1:
$trigger = New-JobTrigger -Once -At 9:00AM -RepetitionInterval (New-TimeSpan -Hours 12) -RepeatIndefinitely
# Var2:
$trigger = New-JobTrigger-Daily -At 9:00AM
# Example 2 (every 5 minutes from 10:00 AM without any limit)
$trigger = New-JobTrigger -Once -At 10:00AM -RepetitionInterval (New-TimeSpan -Minutes 5) -RepeatIndefinitely
# Example 3 (every Monday, Wednesday, and Friday at 12:00 AM)
$trigger = New-JobTrigger -Weekly -DaysOfWeek 1,3,5 -At 12:00AM
# Get user credential so that the job has access to the network
$cred = Get-Credential -UserName <domain>\<someuser>
# Set job options
$opt = New-ScheduledJobOption -RunElevated -RequireNetwork
# Register Job
Register-ScheduledJob -Name <Name> -Trigger $trigger -Credential $cred `
-FilePath <scriptpath> -MaxResultCount 10 -ScheduledJobOption $opt
# Displaying scheduled jobs
get-scheduledjob | ft -auto