What exception type should be used in Powershell to catch a XML parse error due to invalid characters? What exception type should be used in Powershell to catch a XML parse error due to invalid characters? powershell powershell

What exception type should be used in Powershell to catch a XML parse error due to invalid characters?


Here is a way to discover yourself the full type name of an Exception, the result here gives System.Management.Automation.ArgumentTransformationMetadataException as given by @Adrian Wright.

Clear-Hosttry {    [xml]$xml = Get-Content "c:\Temp\1.cs" # line 2}catch {    # Discovering the full type name of an exception    Write-Host $_.Exception.gettype().fullName    Write-Host $_.Exception.message}


System.Management.Automation.ArgumentTransformationMetadataException