-
Notifications
You must be signed in to change notification settings - Fork 0
Scheduling Scripts
Luke Skrzypek edited this page Dec 3, 2024
·
1 revision
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' or pwsh.exe
as the program and '-File "C:\Users\MyUser\Documents\script.ps1"' as the argument. You can also add a script to the 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.