Help with Importing a Scheduled Task XML

0
2
Asked By CuriousCoder42 On

I'm trying to import a scheduled task that I exported via the GUI. I made some edits to a few fields in the XML, but unfortunately, I'm encountering an error when I try to import it back in. Specifically, I get this error: `Register-ScheduledTask : The task XML contains a value which is incorrectly formatted or out of range.` I've double-checked the XML and ensured I've used the 'preservewhitespaceoption' while editing. My main concern is a `Priority` value set to 100, which I think might be causing the issue since it should be between 0-10, according to the documentation. Has anyone else faced this, or can you provide any insights into resolving this?

4 Answers

Answered By PowershellGuru On

An effective method I've found is to export from the task scheduler and load the XML into a variable using a Here-string. Here’s how you can do it:

```powershell
$XML = @'

'@
Register-ScheduledTask -Xml $XML -TaskName ''
```
This often helps bypass errors you might face with improper XML edits.

CuriousCoder42 -

I did something similar, but I think my `Priority` setting threw a wrench in the works. I appreciate your input!

Answered By ScriptingSamurai On

Just a heads up, the XML method can sometimes be finicky across different environments. I've started using PowerShell scripts to create tasks from scratch for better reliability. For example, I’ve scripted a nightly reboot, which you might find useful as a reference!

CuriousCoder42 -

Thanks for the suggestion! I wanted the XML for specific fields, but your example could be a great fallback.

Answered By TaskMaster99 On

It looks like the `Priority` line is indeed the culprit here. You should set it to a value within the range of 0-10. The documentation you can refer to is [here](https://learn.microsoft.com/en-us/windows/win32/taskschd/tasksettings-priority). Changing that should solve your problem!

XMLFixer88 -

I'm pretty sure that's the issue too. It’s a strict requirement, so I’d suggest updating it to a priority value of 10 as you mentioned.

Answered By TechieTina On

Make sure not to change the XML format. Stick with UTF-16 LE encoding, as that's the default. I deploy several XML definitions without any issues, so it may help if you double-check that.

CuriousCoder42 -

Thanks for the tip! I’m using UTF-16, but I’ll recheck the formatting just to be sure.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.