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.