Welcome to an article on How to schedule a task to run a PowerShell script using Task Scheduler on our Windows Server.
In our project, we went through many scenarios where we did not have time to create a timer job for some basic functions but we needed a schedule to happen without creating timer jobs. We can achieve the same by using PowerShell script and schedule it using Task Scheduler. It will save your time and effort in creating a timer job as building a PowerShell script is easy. It will work the same way as you expect from a timer job.
How? Let’s see it.
Go to Window’s Start Button.
Search for a Task Scheduler.
Once you find it, click on it.
You will see the screen below.
On the right corner, Click on Create Task.
You will see the following dialog box that will pop up.
Configure the General Tab with the following details.
Name - Provide a name for the job.
Description - Description states why you are running this job.
User - You can state under whose user ID, this should run. You should always select the admin ID.
You can choose, if you want to run the job with highest privileges.
Once done, click on Triggers Tab.
1. Click on New Button.
2. You can configure whether you want to run this schedule once or daily or weekly or monthly
according to your scenario.
One configured, Click on the Actions Tab.
Click on the New button to configure the action.
Configuration
This is the most important part where most of the users go wrong.
Action - As action, select “Start a program”.
Program/script - Here type in “powershell”.
Add arguments (optional) - It is not optional. Provide a path to your script as the following -file "C:\MyScriptSchedule\Schedule.ps1".
Once configured, you can set any Condition if you have to run this scheduled job.
On the Settings tab, you can see; if you need to do any modification. I took the default settings.
Click OK.
It will ask the password of the admin ID, you are running schedule with.
Sit and relax. Your schedule will run as expected according to your schedule without any issue.
In this article, we saw how to schedule a task to run a PowerShell script using Task Scheduler.
Comments