During one of my adventures into the world of PowerShell I came across the following error:

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


[xml]$XmlDataCannot process argument transformation on parameter 'VARName'. PowerShell powershell



$name = XmlData.Name











Then I’m calling the above function

[xml]$somexml = …

Get-XmlData -XmlData $somexml

This is where the above error appears.


I came across a solution here:


After a bit of trying out I found an easier solution:

In my function I changed my Parameter to the type of string


and then within my function I convert the string into Xml.

[xml]$XmlDataXml = $XmlData



Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: