How to: Run a Powershell script from a Scheduled Task

How to: Run a Powershell script from a Scheduled Task/Task Scheduler

I don’t know why, but this is one of those things I forget every. single. time I need to do it.
It’s pretty much a one liner, and yet, here we are! Hopefully this can save some of you a few minutes of messing around.

Step one – create your scheduled task and populate your usual parameters:

As you would usually, create you scheduled task, give it a name, define the trigger(s), etc…

Step two – calling the Powershell script:

Now the part I always forget.
I know, even most novices know how to do this, but I just can’t make it stick!

Create your action and choose to “Start a program“.
We want to call the program/script and specify a few additional arguments.

Fill in “Program/script”:

Powershell.exe

Underneath “Add arguments“, fill in the below:

-ExecutionPolicy Bypass -File “C:\scripts\yourfile.ps1”

That’s it!
Your script should now run successfully under the conditions you specified, earlier!

Here’s a quick screenshot of how it should look:

To quickly explain what’s happening, we are too lazy to sign our scripts, so we add the -ExecutionPolicy Bypass parameter to tell Powershell to temporarily set the Execution Policy to allow our script to run, despite not being digitally signed.

Finally, we pass it a -File that we wish to run. This must be surrounded by quotes, or the script will not run!

 

 

0 comments