Cannot process argument transformation on parameter ‘Environment’. Cannot convert value “System.Xml.XmlElement” 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.”First I’ll explain what I’m trying to do.I’ve got a PowerShell function that takes xml as a parameter
function Get-XmlData{param( [xml]$XmlDataThen I’m calling the above function)begin{$name = XmlData.Name}process{}end{} }
[xml]$somexml = …Get-XmlData -XmlData $somexmlThis is where the above error appears.
Solution
I came across a solution here:http://stackoverflow.com/questions/18040841/passing-an-xmlelement-to-a-background-job-in-powershellAfter a bit of trying out I found an easier solution:In my function I changed my Parameter to the type of string  param( [string]$XmlData )and then within my function I convert the string into Xml.
[xml]$XmlDataXml = $XmlData
Frequently asked questions
What type mismatch does the PowerShell error describe?
It reports an attempt to convert a System.Xml.XmlElement value to System.Xml.XmlDocument, rejecting the node type during parameter transformation.
How did the author work around the parameter conversion?
The function parameter was changed to string, then the string was converted to XML inside the function. This is the workaround demonstrated for that example.

