How to use the Windows Task Scheduler to run a Powershell script
Task Scheduler allows for scheduling periodical tasks under Windows. To launch it follow the directions below:
- Start->Administrative Tools->Task Scheduler.
- Action->Create Task.
Task Scheduler management console will appear. It will look somewhat similar to what is shown in Figure 1:
Figure 1:
In order to schedule a new task select the “Create Task…” option from the “Actions” menu on the right. Configuration window will appear (Figure 2). It is necessary to provide the basic information about the task:
- Task name – it will be visible under this name in the list of task
- Checkbox “Run whether user is logged or not” should be checked – otherwise the task will not run if the user is logged off.
- Check that the right user account for the task is being provided
Figure 2:
Then it is necessary to specify when the task is supposed to be executed. This configuration can be done under the “Triggers” tab. Figure 3 shows an example of the trigger configuration.
Figure 3:
Next step is to configure the action to be executed. This is done in the “Actions” tab. If one wishes to run a Powershell script then it is important to use the appropriate syntax (see also Figure 4):
- Program/script:
cmd.exe
- Add arguments (optional): /c "powershell C:\Backup\transferFile.ps1"
Figure 4:
The last two tabs: “Conditions” and “Settings” contain specific options that allow for further customisation of the task behaviour. Figure 5 and 6 show sample settings.
Figure 5:
Figure 6:
After the task has been created, an additional tab becomes accessible: “History”. It displays all the information about the status of the particular task. There are logs which allows as to checks whether the task was completed successfully or whether it has failed.
Figure 7:
--
JoannaHulboj - 25-Oct-2010