Menu & Search
Running PowerShell Scripts as Scheduled Tasks in Windows

Running PowerShell Scripts as Scheduled Tasks in Windows

When you need something scheduled in Windows, the Task Scheduler is the tool at-hand.

Running PowerShell (.ps1) scripts as Scheduled Tasks is done differently than differently than running regular .bat scripts. Sometimes I forget how it’s done, so a worthy enough post.

Below I’m creating a daily reboot by calling PowerShell script in Task Scheduler on Windows Server 2016.


Create Scheduled Task to Trigger a PowerShell Script

1. Open Task Scheduler.

Task Scheduler New Task

2. Right-click and Create New Task.

New Scheduled Task General Tab

I’ve given it a Name and Description here. In work-life, I’d usually be running these sort of jobs with an AD service account. As well as that, if you’re running a local only PowerShell script then we don’t need to store the password as per the Security options above.

3. Create a schedule within the Triggers tab.

Scheduled Task Triggers Tab

Remember, we can set schedules on many things (e.g. Windows Events or when the server is Idle).  

4. Create a new Action within the next tab. PowerShell scripts require the {powershell} program name as shown, as well as the {-File “C:\Temp\powershell_script.ps1} argument.

Scheduled Task Edit Action
Scheduled Task Actions Tab

5. Next, configure Conditions & Settings – read through what suits your job. The only thing I’ve changed is for it to stop if the task runs longer than 1 hour.

Scheduled Task Settings Tab

6. Finally, verify it’s working by losing connectivity!

PowerShell Scheduled Task Daily Reboot

Share

0 Comments