Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to take my tasks on a non-clustered server, and import them as clustered tasks on a new cluster that has been built and tested.

Here's what I have tried:

$xmlContents = get-content $xmlFilename
Register-ClusteredScheduledTask -TaskName "TestXMLTask" -TaskType AnyNode -Xml $xmlContents

The XML imports okay into the Windows Task Scheduler, but then it is not a "Clustered" task.

Here is the error I get when I run the above code:

Register-ClusteredScheduledTask : Cannot process argument transformation on parameter 'Xml'. Cannot 
convert value to type System.String.
At C:\Users\nwalters\Documents\TestWebSampleCode4FromXML.ps1:4 char:80
+ Register-ClusteredScheduledTask -TaskName "TestXMLTask" -TaskType AnyNode -Xml $ ...
+                                                                                ~
    + CategoryInfo          : InvalidData: (:) [Register-ClusteredScheduledTask], ParameterBindingArgumen 
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Register-ClusteredScheduledTask

Thinking that it wants an XML Doc, I also tried this:

$xmlContents = get-content $xmlFilename
$xmlDoc = [xml] (get-content $xmlFilename)
$test = $xmlDoc.OuterXml
#Write-Host $test
Register-ClusteredScheduledTask -TaskName "TestXMLTask" -TaskType AnyNode -Xml $xmlDoc

I open the file, changed UTF16 to UTF8 and resaved it, shut the different filename from the first example.


Register-ClusteredScheduledTask : The task XML is malformed.
(1,2)::ERROR: incorrect document syntax
At C:\Users\nwalters\Documents\TestWebSampleCode4FromXML.ps1:7 char:1
+ Register-ClusteredScheduledTask -TaskName "TestXMLTask" -TaskType AnyNode -Xml $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (PS_ClusteredScheduledTask:Root/Microsoft/...edScheduledTask) 
    [Register-ClusteredScheduledTask], CimException
    + FullyQualifiedErrorId : HRESULT 0x8004131a,Register-ClusteredScheduledTask

If the XML is really malformed, then how was I able to load it and get to the .OuterXml?

share|improve this question
up vote 3 down vote accepted

The -Xml parameter expects the xml input as a string.

Get-Content, by default, returns an array of strings (one for each line), which is why the first error is thrown.

To get around this, use the -Raw parameter when calling Get-Content to have it return a single string:

$xmlContents = Get-Content $xmlFilename -Raw

Prior to PowerShell 3.0, you can achieve the same thing by piping the string array to Out-String:

$xmlContents = Get-Content $xmlFilename | Out-String
share|improve this answer
That got past XML problem, now getting same error as reported here:… (when not using XML). I thought maybe XML would be the way to get around the other error. – NealWalters Aug 27 '14 at 13:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.