How to: Use Task Scheduler to run Powershell Scripts

This sounds really easy but it can be challenging if you have never done it before. Out of the box Windows does not want to run Powershell scripts in an automated fashion. There are some security hurdles put in place for this reason. This blog post will show you what you need to know to make Powershell task scheduling a breeze.

I am not going to go through creating a Powershell script. That is the subject of another blog post. In this post we will expect that you have a script that you are already running manually and need to schedule it using the task scheduler.

Open the Task Scheduler and configure a basic task with these parameters:

PS_Task_Scheduler1

 

 

PS_Task_Scheduler2

 

Using the –ExecutionPolicy Bypass argument allows us to bypass the script execution restrictions that all Windows operating systems have enabled by default. This is best because it does not remove the security barriers. We will just go around them when the script runs. The “Add arguements (optional): text box needs to have your script name with a “.\” proceeding it. This an execution parameter that tells Powershell to execute the name as a program or script. Finally, we need to tell the task where to look for the script. In this case it is C:\Scripts.

 

PS_Task_Scheduler3

 

Yes we want to append the argument.

 

PS_Task_Scheduler4

 

We still need to add some details to this script before it will run.

 

PS_Task_Scheduler5

 

We need to tell the task who to run the task as. I recommend using an account that has local admin rights that is not an account named Administrator. If you decide you don’t want to use a local Administrator account, you must choose an account that has the “Log on as a batch job” user right in the local security policy. Click “Run whether or not the user is logged on or not” and check the box that says “Run with the highest privileges”.

Click OK. Then if prompted, enter the credentials of the account being used to run the script.

That should be all you need. If you have trouble, make sure you look into the Event logs for clues as to what is going wrong. Powershell has its own event log trap. Find it here:

 

PS_Task_Scheduler6

 

Happy Powershelling!

 

 

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s