title: PowerShell Scheduled Task RegisterTask Method
body: <p>I am attempting to use powershell v2.0 to create a scheduled task using the Schedule.Service Com Object. 
  I have created ps1 file but we get an error when we execute it that is eluding me. 
  Here is the code:</p>
  
  <pre><code>param(
      [string]$xmlFilePath = $(throw "-xmlFilePath is required"),
      [string]$server = "localhost",
      [string]$taskFolderName = "\"
  )
  
  try {
      $xmlContent = [xml] (Get-Content $xmlFilePath);    
      $taskScheduler = New-Object -ComObject Schedule.Service
      $taskScheduler.Connect($server) 
      $taskFolder = $taskScheduler.GetFolder($taskFolderName);
      $taskFolder.RegisterTask($xmlFilePathl, $xmlContent, 6, "&lt;user name&gt;", "&lt;password&gt;", 1);
  }
  catch {
      $Exception = $_.Exception;
      while ($Exception.Message -ne $null)
      {   
         Write-Error $Exception.Message;
         $Exception = $Exception.InnerException;
      }
      return; 
  }
  </code></pre>
  
  <p>Runnig this locally or remotely gives the same result.
  The error is as follows:
  C:\temp\CreateScheduledTaskFromXML.ps1 : Exception calling "RegisterTask" with "6" argument(s): "(1,2)::"
  At line:1 char:33
  + .\CreateScheduledTaskFromXML.ps1 &lt;&lt;&lt;&lt;  -server DEVBDAPP12 -xmlFilePath "C:\Temp\collectors\adcomputer\Discovery.Ser
      vices.ActiveDirectory.Computer.Collector.xml"
          + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
          + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CreateScheduledTaskFromXML.ps1</p>
  
  <p>What does this mean "Exception calling "RegisterTask" with "6" argument(s): "(1,2)::""
  The failure is occuring on the registertask method but the error does not make sense.
  This use is based on the following MSDN article
  <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa382575(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/aa382575(v=vs.85).aspx</a></p>
  
  <p>As a side not, We cannot update this machine to powershell 3.0 or use the powerpack at this time and would like to avoid schtask.exe so these are not options</p>
  
  <p>If anyone has any insight it would be greatly appreciated.</p>