Skip to content

Instantly share code, notes, and snippets.

Embed
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")
$sch.connect("computername")
$root=$sch.GetFolder("\")
$root.CreateFolder("subfolder")
$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)
}
#Export
$folder.getTasks(0) | % {
$path="c:\temp\tasks\$($_.name).xml"
$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
You can’t perform that action at this time.