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.

PowerShell

1

2

3

4

5

6

PSC:\>$task=Get-ScheduledTaskDailyMSInfo

PSC:\>$task

TaskPath TaskName State

---------------------

\MyCompany\Reporting\DailyMSInfo Ready

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

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:

PowerShell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

PSC:\>$task.Author="Jeff Hicks"

PSC:\>$task.Description="create a daily MSINfo32 Report"

PSC:\>$task.version="1.0"

Some properties are part of the nested Settings object.

PSC:\>$task.settings

AllowDemandStart:True

AllowHardTerminate:True

Compatibility:Vista

DeleteExpiredTaskAfter:

DisallowStartIfOnBatteries:True

Enabled:True

ExecutionTimeLimit:PT72H

Hidden:False

IdleSettings:MSFT_TaskIdleSettings

MultipleInstances:IgnoreNew

NetworkSettings:MSFT_TaskNetworkSettings

Priority:7

RestartCount:0

RestartInterval:

RunOnlyIfIdle:False

RunOnlyIfNetworkAvailable:False

StartWhenAvailable:False

StopIfGoingOnBatteries:True

WakeToRun:False

DisallowStartOnRemoteAppSession:False

UseUnifiedSchedulingEngine:False

MaintenanceSettings:

volatile:False

PSComputerName:

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

PowerShell

1

2

PSC:\>$task.settings.Compatibility="Win8"

PSC:\>$task.Settings.RunOnlyIfNetworkAvailable=$True

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

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

PowerShell

1

PSC:\>get-scheduledtaskDailyMSInfo|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.

PowerShell

1

2

3

4

5

PSC:\>get-scheduledtaskDailyMSInfo|Disable-ScheduledTask

TaskPath TaskName State

---------------------

\MyCompany\Reporting\DailyMSInfo Disabled

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:

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.

MEMBER LOGIN:

BECOME A PETRI MEMBER:

About the Contributor

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, teacher and consultant. Jeff has written for numerous online sites and print publications and is a frequent speaker at technology conferences and user groups. His latest book is PowerShell Scripting and Toolmaking.