Create Windows Scheduler Task by PowerShell Automation

In this article we will see simple steps to configure windows scheduler tasks using PowerShell Automation.

This article can be useful in conjunction with some of the earlier articles that I have written on Process Automation using PowerShell

Before getting into the code, let see the Windows Task Manager to understand where we can find tasks which are getting created by the code

Type “Task Manager”

1

You can see the highlighted section where you can find newly created Tasks

2

The code is pretty simple and based on standard PowerShell Command-lets as described below:

3

In Step 1, we are defining Trigger for the Task by using “New-ScheduledTaskTrigger” Command-Let. It could be any permissible Time Unit as shown below

4

In Step 2 & 3 we are setting up User Name and Password that the Task will be used as Owner Account to run the defined action

In Step 4 we are defining the action by using “New-ScheduledTaskAction” Command-Let that needs to be executed by the task when trigger reached, in this demo this task will execute a PowerShell script

Finally in Step-5 we are registering the tasks by using “Register- ScheduledTask” Command-Let. This Command-Let takes Name, Trigger, UserName, Password and Action as input parameter (as defined in above steps)

Once the script gets executed a new task will be added to the Windows Task Scheduler

5

We can see the new task added in Task Scheduler Window as shown below:

6

If we double click the this task, it will open the task configuration screen that we can use verify the task properties as explained below-

General Tab: Here we can see the name of the Task & User Account that will be used to execute the defined action

7

Triggers Tab: Here we can see the Trigger defined for this task

8

Actions Tab: Here we can see the action defined for this task. In this demo we have specified a PowerShell Script to be executed whenever respective trigger achieved

9

In case if you make any changes to this task Windows will present you a password dialog to confirm the User Credentials, If asked enter the respective credentials

10

This is a simple implementation that allows you to configure Windows Tasks using PowerShell Automation.

That is all for this demo.

Hope you find it helpful.

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