PowerShell Remoting Serialization and Deserialization PowerShell Remoting Serialization and Deserialization powershell powershell

PowerShell Remoting Serialization and Deserialization


They have published the PowerShell Remoting Specification which would give you the spec, but the source code they used to implement it is not public at this time. http://msdn.microsoft.com/en-us/library/dd357801(PROT.10).aspx


Oh, I see what you're asking, you're looking for a ConvertTo-CliXml similar to how ConvertTo-Csv works in place of Export-Csv. At first glance it sounds like you're trying to avoid CliXml entirely.

In that case, there's one on PoshCode: ConvertTo-CliXml ConvertFrom-CliXml

Here's a verbatim copy to give you an idea (I haven't checked this for correctness):

function ConvertTo-CliXml {    param(        [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]        [ValidateNotNullOrEmpty()]        [PSObject[]]$InputObject    )    begin {        $type = [PSObject].Assembly.GetType('System.Management.Automation.Serializer')        $ctor = $type.GetConstructor('instance,nonpublic', $null, @([System.Xml.XmlWriter]), $null)        $sw = New-Object System.IO.StringWriter        $xw = New-Object System.Xml.XmlTextWriter $sw        $serializer = $ctor.Invoke($xw)        $method = $type.GetMethod('Serialize', 'nonpublic,instance', $null, [type[]]@([object]), $null)        $done = $type.GetMethod('Done', [System.Reflection.BindingFlags]'nonpublic,instance')    }    process {        try {            [void]$method.Invoke($serializer, $InputObject)        } catch {            Write-Warning "Could not serialize $($InputObject.GetType()): $_"        }    }    end {            [void]$done.Invoke($serializer, @())        $sw.ToString()        $xw.Close()        $sw.Dispose()    }}