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.
2. Right-click and Create New Task.
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.
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.
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.
6. Finally, verify it’s working by losing connectivity!
Leave a Reply