Help with Importing a Scheduled Task XML

April 24, 2025 4 answers
Asked by +try a different route
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?

Answers

+!rhyming dictionary
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.

+try a different route: Thanks for the tip! Iโ€™m using UTF-16, but Iโ€™ll recheck the formatting just to be sure.

Reply to this answer
quilt guild
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!

tenseMark-B: 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.

Reply to this answer
Chalky
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!

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

Reply to this answer
permission to disagree
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.

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

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions