Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Import & export of scheduled tasks using scheduler service
# create task from its xml definition
$sch = New-Object -ComObject("Schedule.Service")
$folder =$sch.GetFolder("\subfolder")
#import .xml
Get-childItem -path $task_path -Filter *.xml | %{
$task_name = $_.Name.Replace('.xml', '')
$task_xml = Get-Content $_.FullName
$task = $sch.NewTask($null)
$task.XmlText = $task_xml
$folder.RegisterTaskDefinition($task_name, $task, 6, $cred.UserName, $cred.GetNetworkCredential().password, 1, $null)
$folder.getTasks(0) | % {
$x=New-Item -ItemType file -Path $path
Set-Content -Path $path -Value $_.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment