Schedule a PowerShell script to run on a Windows Server

schedule a powershell script to run
Spread the love


Windows Administrators create PowerShell scripts to automate certain routine admin tasks. After creating these scripts, you might need to run the script on a regular schedule. This article will show you how to configure your PowerShell script to run on regular basis using Windows Task Scheduler. It will cover dealing with issues relating to execution policy, run as account and much more.


To complete this task, you require the following:
1. A Powershell script. For the purpose of this article, I will call mine samplescript.ps1
2. A Windows Server 2008 (minimum) – The task outlined in this article was carried out on a windows server 2008.


  1. Copy your script to a folder in your windows server – I will use D:\Scripts\samplescript.ps1 for illustration.
  2. Open Task Scheduler on your windows server:
    1. Click start and type task scheduler:
    2. Click on task scheduler
    3. search_task_scheduler
    4. The task scheduler window opens
    5. task_scheduler_first_windowOn the task scheduler window, click Create task to open the Create Task window:
    6. create_task_general_windowEnter a name and description for your task. The general tab allows you to configure security options – Under what security context will the task run, will the task only run when a user is logged on or not (select Run whether a user is logged on or not). You can also configure whether this task is scheduled for a Windows 7, Windows Server 2008 or Windows Server 2003, Windows XP, or Windows 2000. Select Windows 7, Windows Server 2008.
  3. Click Triggers tab. This tab allows you to configure what triggers the task. Effectively, you are configuring what will make the task run. This is where you configure the actual scheduling.
  4. create_task_triggers_window
  5. On the Triggers tab, click New… and configure your schedule. A sample is shown below:
  6. create_task_triggers_window_new_trigger
  7. When you finish, click Ok.
  8. Click Actions tab: This is where the main task for this article is configured. In the actions tab, you will configure your PowerShell script to run. But you will have to add an action that sets your execution policy first.
    1. Click New to add your first action: configure execution policy.
    2. On the Action drop-down, select Start a program.
    3. On the Program/script windows, type the full path to your PowerShell installation – Most likely to be: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    4. Beside arguments (optional), enter: Set-ExecutionPolicy Unrestricted -Force. Your script is likely to fail if you do not set execution policy this way. I have tried setting execution policy inside my script but it did not work. This approach works for me.
    5. create_task_actions_window_new_action_1
    6. When done with your configuration, click Ok.
    7. On the Actions tab, click New to add your second action: configure your PowerShell script to run. Actions run in sequence, so your script will run after the set execution policy action has completed:
      g. On the Program/script windows, type the full path to your PowerShell installation – Most likely to be: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    8. Beside arguments (optional), enter: .\samplescript.ps1 (Change to your script name but note the dot (.) and the backslash (\).
    9. On the Start in (optional), enter the directory containing your script, for example D:\Scripts\.
    10. create_task_actions_window_new_action_2
    11. Click Ok, to save your task. If you receive a Task Schedule confirmation, click Yes:
    12. create_task_actions_window_new_action_3
    13. Note: The default configuration on the Conditions and Settings tabs are okay but you may configure it if you wish.
    14. Now that you have added all your parameters, on the Create Task window, click Ok, to save your changes.


I have scheduled a number of tasks to run my PowerShell scripts using this procedure. If this does not work for you or if you experience any problem, please leave questions and / or comments.

This article is available in the following places:

TechNet Wiki

Spread the love

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

By using this website you agree to accept our Privacy Policy and Terms & Conditions