# encoding: ascii
# api: powershell
# title: ConvertFrom-CliXml
# description: I wrote this based on ConvertTo-CliXml. This takes a xml string from the pipeline and converts it to objects.
# version: 0.1
# type: function
# author: David Sjstrand
# license: CC0
# function: ConvertFrom-CliXml
# x-poshcode-id: 2294
# x-archived: 2014-01-03T12:11:21
# x-published: 2011-10-10T14:57:00
#
#
function ConvertFrom-CliXml {
param(
[parameter(position=0,mandatory=$true,valuefrompipeline=$true)]
[validatenotnull()]
[string]$string
)
begin
{
$inputstring = ""
}
process
{
$inputstring += $string
}
end
{
$type = [type]::gettype("System.Management.Automation.Deserializer")
$ctor = $type.getconstructor("instance,nonpublic", $null, @([xml.xmlreader]), $null)
$sr = new-object io.stringreader $inputstring
$xr = new-object xml.xmltextreader $sr
$deserializer = $ctor.invoke($xr)
$method = @($type.getmethods("nonpublic,instance") | where-object {$_.name -like "Deserialize"})[1]
$done = $type.getmethod("Done", [reflection.bindingflags]"nonpublic,instance")
while (!$done.invoke($deserializer, @()))
{
try {
$method.invoke($deserializer, "")
} catch {
write-warning "Could not deserialize $string: $_"
}
}
}
}