• subscribe
October 24, 2011 09:00 AM

PowerShell Script: Rename Scheduled Tasks in Windows 7, Windows Server 2008, and Windows Vista

PowerShell script makes a Task Scheduler limitation less annoying
Windows IT Pro
InstantDoc ID #140368
Downloads
140368.zip

The Task Scheduler service in Windows is a very useful automation tool. Starting with Windows Vista and Windows Server 2008, the Task Scheduler service got an overhaul. It has new trigger types, actions, and task folders. It also has a built-in scriptable object interface for managing scheduled tasks. (Microsoft provided a scriptable object interface for the Task Scheduler in earlier Windows versions, but it was a separate download.) Figure 1 shows the updated Task Scheduler window on a Windows 7 computer.

Figure 1: Windows 7 Task Scheduler
Figure 1: Windows 7 Task Scheduler

In Windows Server 2003, Windows XP, and Windows 2000, scheduled tasks are .job files found in the computer's \%SystemRoot%\Tasks folder. In these OS versions, renaming a task is easy: Press F2 when the task is highlighted in Windows Explorer or right-click the task in Task Scheduler and select Rename. In Windows 7, Vista, and Server 2008, Task Scheduler tasks are no longer stored as .job files in the Tasks folder, so you can’t rename a scheduled task after you create it.

I don't know the reasons for the omission of this seemingly simple feature, but there is a workaround: Export the task as an XML file, import the task to create a new task with the new name, then delete the old task. This seemed like an unnecessary amount of extra work, so I wrote a PowerShell script, Rename-ScheduledTask.ps1, to make renaming a task easier.

To download Rename-ScheduledTask.ps1, click the 140368.zip hotlink at the top of the article. The script works on only Windows 7, Vista, and Server 2008 for two reasons. First, this script isn’t needed in earlier OS versions. Second, the script object interface it uses isn't present in earlier OS versions. You can use the script to rename tasks on the local machine and remote computers. If you want to rename a task on the local computer, you must run the script from an elevated PowerShell window (i.e., right-click the PowerShell shortcut and choose Run as administrator). 

How to Use the Script

The script's command-line syntax is as follows:

Rename ScheduledTask

  [ TaskName] <String>

  [ NewName] <String>

  [ ComputerName <String>]

  [ ConnectionCredential <PSCredential>]

  [ TaskCredential <PSCredential>]

The only required parameters are -TaskName and -NewName, which you use to specify the task's current name and new name, respectively. Because the -TaskName and -NewName parameters must be the first and second parameters on the script's command line, including the parameters' names (-TaskName and -NewName) is optional.

The overhauled Task Scheduler service supports task folders. If you specify a task name without a task folder name, the script assumes the task is in the root tasks folder ("\"). You can relocate a task to a different task folder by specifying the task folder's name as a part of the task's new name. The task folder will be created if it doesn't exist. For example, the command

Rename ScheduledTask

  "My Task"

  "\User Tasks\User Task 1"

renames the task named \My Task to \User Tasks\User Task 1. The \User Tasks folder will be created if it doesn't exist.

You use the -ComputerName parameter to specify the computer where the task to be renamed is stored. You can't move tasks between computers, so the renamed task will also be stored on that computer. If you omit the -ComputerName parameter, the script assumes the task to be renamed is on the current computer.



ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here