Created
September 20, 2013 07:36
-
-
Save kayasax/6634393 to your computer and use it in GitHub Desktop.
Import & export of scheduled tasks using scheduler service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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