title: How to use xml file as a parameter input for script
body: <p>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.</p>
  
  <p>How I have the param xml input code currently:</p>
  
  <pre><code>param([xml] $xmlData)
  </code></pre>
  
  <p>But when the script is executed I get this error:</p>
  
  <pre><code>PS&gt; .\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
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>PS&gt; $xml = [xml] (gc xmlfile.xml)
  
  PS&gt; $xml.GetType()
  
  IsPublic IsSerial Name                                     BaseType
  -------- -------- ----                                     --------
  True     False    XmlDocument                              System.Xml.XmlNode
  </code></pre>
  
  <p>As a last note, my xml file does contain the xml version tag  and the structure is simple:</p>
  
  <pre><code>&lt;root&gt;
  &lt;value1&gt;...
  &lt;value2&gt;...
     &lt;subnode&gt;...
     &lt;subvalue1&gt;...
  </code></pre>
  
  <p>I'm skipping the closing tags and everything.</p>