PowerShell Script implementation Example of adding and modifying a task plan _powershell

Source: Internet
Author: User

PowerShell can read or modify all information for a scheduled task. However, please note that the small series is tested on the Windows7,windows 2008, seemingly Windows2003 seems to have some differences.

Here is an example, the small part to demonstrate is to modify \microsoft\windows\rac\ractask this task Ractimetrigger trigger, set it to enable state. The general idea is to create the object first and connect to the Task Scheduler. Then locate the task's directory and the task itself. And then you get the trigger for the task by the definition of the task, and after you find the Ractimetrigger trigger, set its Enable property to $true. Finally, the object is updated to the Task Scheduler. Look at the steps below:

Copy Code code as follows:

# Connect to Task Scheduler first
$service = New-object-comobject Schedule.service
$service. Connect ($env: COMPUTERNAME)

# Select a task in the specified directory, small series here to test the use of \microsoft\windows\rac\ractask this task:
$folder = $service. GetFolder (' \microsoft\windows\rac ')
$task = $folder. Gettask (' Ractask ')

# Gets the definition of the task by defining the trigger for the fetch task, and then selecting the trigger with the ID ' Ractimetrigger ' in the trigger, and finally setting it to the enabled state.
$definition = $task. Definition
$definition. Triggers |
where-object {$_.id-eq ' Ractimetrigger '} |
Foreach-object {$_. Enabled = $true}
#注意, the update here simply updates the properties of the PowerShell cached object and does not actually update to Schedule.service (Task Scheduler)

# Write updates back to the Task Scheduler
$folder. Registertaskdefinition ($task. Name, $definition, 4, $null, $null, $null)
#注意: 4 of the above parameter indicates update. The return value of the registertaskdefinition () function is the definition of the $task task.


As for the modification of the Task Scheduler, the small series demonstrates so much.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.