Skip to content

Instantly share code, notes, and snippets.

@kayasax
Created September 20, 2013 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kayasax/6634393 to your computer and use it in GitHub Desktop.
Save kayasax/6634393 to your computer and use it in GitHub Desktop.
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