How to Modify, Schedule and Launch Scheduled Tasks in Windows 8 and Server 2012

Posted on November 20, 2012 by Jeff Hicks in PowerShell with 0 Comments

We’ve been looking at how to manage scheduled tasks in Windows 8 and Windows Server 2012 using PowerShell. In part one of this series, I showed you how to use the ScheduledTasks module to retrieve information about scheduled tasks. In part two, I walked you through creating a new scheduled task using PowerShell that would run daily.

Let’s see what else we can do with it. In this final installment, we’re going to learn how to manage scheduled tasks in Windows 8 and Windows Server 2012, specifically, how to modify a scheduled task, manually launch a scheduled task, disable and enable a task, and remove a scheduled task.

First, I’ll save the task to a variable so I don’t have to keep getting it.

The task object has a number of properties that can be set as you can see in Figure 1.

Manage Scheduled Tasks Windows 8 Windows Server 2012 : Scheduled Task Object

How to Modify a Scheduled Task

I think the easiest way to modify a scheduled task is to assign new values to the scheduled task object. Some properties you can modify like this:

Many of these are properties of the task you see in the Task Scheduler. I’ll go ahead and modify some of these.

Sponsored

These changes are for the task held in my variable. To apply them to the scheduled task itself I’ll use Set-ScheduledTask.

You have to reapply the credentials the task is going to use. In Part 2 of this series I showed you some other ways of handling credentials.

But now when I refresh the task in Task Scheduler I can see my changes (Figure 2).

Manage Scheduled Tasks Windows 8 Windows Server 2012 : modify scheduled task

How to Manually Launch a Scheduled Task

If necessary, you can also manually launch a scheduled task from PowerShell. You either need to know the task name and path:

Sponsored

Or an easier approach is to get the task, or tasks first and then pipe them to Start-ScheduledTask.

How to Disable and Enable a Scheduled Task

Should the need arise, it is simple to disable a scheduled task. As with Start-ScheduledTask you either need to specify the name and path, or simply pipe a task to Disable-ScheduledTask.

The change is immediate. If you get the task from a remote computer it will be disabled on that computer.
Need to turn it back on? I bet you can guess how to do it. Here’s how to enable a scheduled task:

It really is that easy.

How to Remove a Scheduled Task

Finally, you may have a need to totally remove a scheduled task. For that we unregister the task.

As you can see, this cmdlet supports –Whatif which is helpful if you are running this against a number of machines. To truly remove the scheduled task I can re-run the command omitting –Whatif. PowerShell will prompt you for confirmation.

Managing scheduled tasks with PowerShell is pretty straightforward. There are a few other features that I didn’t cover but these articles should be enough to get you started. Unfortunately, as of the time of preparing these articles, the help content for the ScheduledTask module has not been released, so you might still need to do a little experimentation. If you run into issues, feel free to use the forums at PowerShell.org.

Sponsored

Tagged with ,