title: Importing Scheduled Tasks with Powershell in Windows 2012 R2
body: <p>I am very new to Powershell scripting but have attempted to modify a script that I found <a href="http://jon.netdork.net/2011/03/10/powershell-and-importing-xml-scheduled-tasks/" rel="nofollow">here</a> to import some XML Scheduled Tasks using Powershell in Windows 2012 R2.</p>
  
  <p>I have been successful in importing the Scheduled Tasks into the root [Task Scheduler Library] using this script.</p>
  
  <p>The problem seems to be that the Schedule Tasks need to be imported into a subfolder under Task Scheduler Library, let's say "SubTasks"</p>
  
  <pre><code>$task_path = "C:\Users\me\Desktop\ST Testing\exported ST's\scheduledTask.xml"
  $task_user = "usr"
  $task_pass = "pwd"
  
  $schedule = new-object -com("Schedule.Service")
  $schedule.Connect("server") # servername
  #$folder = $schedule.GetFolder("\") &lt;===This works fine
  $folder = $schedule.GetFolder("\SubTasks") #&lt;===This does not work
  Write-Host $folder
  
  Get-Item $task_path | % {
     $task_name = $_.Name.Replace('.xml', '')
     $task_xml = Get-Content $_.FullName
     $task = $schedule.NewTask($null)
     $task.XmlText = $task_xml
     $folder.RegisterTaskDefinition($task_name, $task, 6, $task_user, $task_pass, 1, $null)
  </code></pre>
  
  <p>}</p>
  
  <p>When I run the above Powershell Script I receive this error:</p>
  
  <blockquote>
    <p>Exception calling "RegisterTaskDefinition" with "7" argument(s): "The 
    specified path is invalid. (Exception from HRESULT: 0x800700A1)"
    At C:\Users\me\Desktop\ST Testing\ImportSTs.ps1:22 char:5
    +     $folder.RegisterTaskDefinition($task_name, $task, 6, $task_user, 
    $task_pass, ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ComMethodTargetInvocation</p>
  </blockquote>
  
  <p>Thanks in advance.    </p>