Register-ScheduledTask

OK this one is driving me nuts.
I have a scheduled task I have exported to an XML file.

I try to import it to another machine using the following code:

$User = "domain\administrator"
$XML = get-content 'C:\Folder1\task.xml'| out-string
Register-ScheduledTask -TaskName "TASK" -Xml $XML -User $User -Password P@ssw0rd -Force

Which returns…

Register-ScheduledTask : The parameter is incorrect.
At line:3 char:1
+ Register-ScheduledTask -TaskName "TASK" -Xml $XML -User $User -Password P@ssw ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTask], CimExc 
   eption
    + FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask

I’m lost, tried all sorts.

Register-ScheduledTask  -Xml (get-content 'C:\Folder1\task.xml'| out-string) -TaskName "TASK" -User $User -Password P@ssw0rd –Force

…returns same result as essentially is same code. But only decent example I could find formats the code like this.

I would very much appreciate any help.

Thanks
Jonathan.

Have you tried delimiting the password in quotation marks?

Hi Don. Thanks for the speedy response!

I have just tried that, returns same error unfortunately. 11:16 PM here, think I’ve looked at it for too long now…

Jonathan

Richard Siddaway wrote:I've found Scheduled Jobs to be a bit flaky and temperamental.

A scheduled job will become corrupt in a number of circumstances:

  • running it using the scheduled task cmdlets – almost always
  • running it through the task scheduler before it’s run once on a schedule – roughly 25% of the time & I can’t tie down the reasons

In PowerShell v4 things are a little better as you have the ability to start the scheduled job through the RunNow parameter for Register-ScheduledJob and Set-ScheduledJob. I’d recommend upgrading to PS 4.0 if you want to use scheduled jobs just for those parameters.

Also once your scheduled job has become corrupt, deleting it and recreating won’t work. The name is preserved somewhere – haven’t tracked it down yet – and the new definition is immediately flagged as corrupted. You need to give the scheduled job a new name

Read this, gave it a new name and it worked.

#Darnit!

I know this topic has been dormant for a while, but I came across it as I was having the same issue.

The good news is I’m pretty sure I’ve tracked down the registry keys that represent the corrupted scheduled task!

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree

Search each for the name of the task you are trying and failing to create.

It did the trick for me!