Skip to content

Scheduling Scripts

Peter Schulz edited this page Apr 12, 2015 · 2 revisions

Scheduling Script

If you want to schedule a PowerShell script to run as an automated task, you can set it up through Task Scheduler using 'powershell.exe' as the program and '-File "C:\Users\MyUser\Documents\script.ps1"' as the argument. You can also add a script to task scheduler from PowerShell directly which is sometimes more handy than filling in all the Task Scheduler options. This script will add a task to run a specified script daily at 2AM:

$trigger = New-JobTrigger -Daily -At "2:00"
Register-ScheduledJob -Name MyScript -Trigger $trigger -FilePath "C:\Users\MyUser\Documents\MyScript.ps1"

Only two lines of PowerShell instead of launching Task Scheduler!

If you later want to view the status or change the schedule, it will be in Task Scheduler in the following location:

Task Scheduler Library > Microsoft > Windows > PowerShell > ScheduledJobs

The name provided after -Name will be the name of the task.

Clone this wiki locally