I have a PowerShell script that must take an xml file as the input source for all the parameters/variables that will be used in the script.
How I have the param xml input code currently:
param([xml] $xmlData)
But when the script is executed I get this error:
PS> .\script.ps1 -xmlData .\xmlfile.xml
script.ps1 : Cannot process argument transformation on parameter 'xmlData'. Cannot convert
value ".\xmlfile.xml" to type "System.Xml.XmlDocument". Error: "The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type."
At line:1 char:22
+ .\script.ps1 -xmlData .\xmlfile.xml
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [script.ps1], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,script.ps1
In a PS session if I do this it works fine and I can see the nodes and data parsed from the xml file, so I'm not sure how this should be done correctly or if I'm missing something:
PS> $xml = [xml] (gc xmlfile.xml)
PS> $xml.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False XmlDocument System.Xml.XmlNode
As a last note, my xml file does contain the xml version tag and the structure is simple:
<root>
<value1>...
<value2>...
<subnode>...
<subvalue1>...
I'm skipping the closing tags and everything.