How to run PowerShell scripts with Windows Task Scheduler



Windows Task Scheduler can be a very useful tool to run your PowerShell scripts on boot, login, on a schedule or other events.

This is a step-by-step tutorial on how you can do this in Windows 10, but the steps in this guide applies to all modern Windows client and Windows server operating systems. Windows Task Schedule is a built in Windows program by default, so no additional software installation are required.

This is how you do it

  • Start Windows Task Scheduler, this can be done by searching for it, or running (START+R) taskschd.msc.
  • Right click on Task Scheduler Library and then select Create Task…. A popup window with the tabs General, Triggers, Actions, Conditions and Settings will appear.

In the “General” tab

  • In the General tab give a name to your task by filling out the Name field.
  • Check Run whether user is logget on or not under Security options
  • Check Run with highest privileges

In the “Triggers” tab

In the Triggers tab you have many options for when you want this task to run, but in this example I will use On a schedule.

  • Select New and then select On a schedule under Begin the task:
  • Here you can select whatever fits your needs, but there is two important things to remember. The first is to select Enabled at the bottom and the second is to make the Start time and date to be in the future. If the start time is passed when the task is created the task will never run, and it will never re-run. Each time you re-configure the task you must also set the time to be in the future.
  • Click OK
Example of trigger that runs every 10 minutes every day

In the “Actions” tab

  • in the Action tab select New and fill as follows:

    Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    This is the link to your powershell.exe file, even if you have a newer version it is located in the v1.0 folder.

    Add arguments (optional):
    -noprofile -executionpolicy bypass -file "C:\powershell_script\test.ps1" (replace with path to script-file).

    The -noprofile parameter start PowerShell without any profiles
    The -executionpolicy bypass parameter Is bypassing any restrictions imposed by the execution policy, this should be safe if you know your code.
    The -file parameter is for opening a file. (your .ps1 script-file)
  • Click OK. You will be prompted to enter credentials for the user that should run the script, this user should have administrative rights.

Testing the Task

A good test to do if you want to see that it works is to make a simple script that output the current date and time to a text-file.

Get-Date >> "c:\powershell_script\testlogg.txt"
Example of a successful run