PowerShell

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

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.

​PS C:\> $task = Get-ScheduledTask DailyMSInfo
PS C:\> $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.

Sponsored Content

Passwords Haven’t Disappeared Yet

123456. Qwerty. Iloveyou. No, these are not exercises for people who are brand new to typing. Shockingly, they are among the most common passwords that end users choose in 2021. Research has found that the average business user must manually type out, or copy/paste, the credentials to 154 websites per month. We repeatedly got one question that surprised us: “Why would I ever trust a third party with control of my network?

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:

​PS C:\> $task.Author = "Jeff Hicks"
PS C:\> $task.Description = "create a daily MSINfo32 Report"
PS C:\> $task.version = "1.0"
Some properties are part of the nested Settings object.
PS C:\> $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.

​PS C:\> $task.settings.Compatibility = "Win8"
PS C:\> $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.

​PS C:\> $task | set-scheduledtask -user "globomantics\administrator" -Password "[email protected]"

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:

​PS C:\> start-scheduledtask -taskname DailyMSInfo -TaskPath MyCompany\Reporting

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

​PS C:\> get-scheduledtask DailyMSInfo | 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.

​PS C:\> get-scheduledtask DailyMSInfo | 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:

​PS C:\> get-scheduledtask DailyMSInfo -CimSession chi-dc03 | Enable-ScheduledTask

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.

​PS C:\> get-scheduledtask DailyMSInfo -CimSession chi-dc03,chi-win8-01 | Unregister-ScheduledTask -WhatIf
What if: chi-dc03: Performing operation 'Delete' on Target '\MyCompany\Reporting\DailyMSInfo'.
What if: chi-win8-01: Performing operation 'Delete' on Target '\MyCompany\Reporting\DailyMSInfo'.

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.

Related Topics:

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register
Comments (1)

One response to “How to Modify, Schedule and Launch Scheduled Tasks in Windows 8 and Server 2012”

Leave a Reply

Don't leave your business open to attack! Come learn how to protect your AD in this FREE masterclass!REGISTER NOW - Thursday, December 2, 2021 @ 1 pm ET

Active Directory (AD) is leveraged by over 90% of enterprises worldwide as the authentication and authorization hub of their IT infrastructure—but its inherent complexity leaves it prone to misconfigurations that can allow attackers to slip into your network and wreak havoc. 

Join this session with Microsoft MVP and MCT Sander Berkouwer, who will explore:

  • Whether you should upgrade your domain controllers to Windows Server
    2019 and beyond
  • Achieving mission impossible: updating DCs within 48 hours
  • How to disable legacy protocols and outdated compatibility options in
    Active Directory

Sponsored by: