Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

cls
$xmlFilename="i:\Scripts\ImportScheduledTasks\CleaupMessageLog.xml" 
$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 
   tTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Register-ClusteredScheduledTask

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

cls
$xmlFilename="i:\Scripts\ImportScheduledTasks\CleaupMessageLogUTF8.xml" 
$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.

Error:

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

1 Answer 1

up vote 2 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: serverfault.com/questions/623407/… (when not using XML). I thought maybe XML would be the way to get around the other error. –  NealWalters Aug 27 at 13:43

Your Answer

 
discard

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.