title: Custom PowerShell Host and Converting PSObject back to base type
body: <p>When hosting the PowerShell runtime is it possible to convert a <code>PSObject</code> back into its original type some how? </p>
  
  <p>For example:</p>
  
  <p>I have a cmdlet that calls <code>WriteObject</code> and pushes a collection of ClassXzy in the pipeline. When I call <code>PowerShell.Invoke</code> from the host end of things I retrieve a collection of <code>PSObject</code>s with a <code>BaseObject</code> property. Casting <code>BaseObject</code> to <code>ClassXyz</code> fails. </p>
  
  <p>Is there any way around mapping each property value to its corresponding original object?<br>
  I'm assuming PowerShell does this somehow as you can pass <code>PSObject</code>s to cmdlets and they get translated to the Parameter types. But how? </p>
  
  <p>I spent along time tearing into the PS assemblies with Reflector but haven't really nailed down how this magic happens. </p>
  
  <p>Any ideas?</p>
  
  <p>EDIT: I forgot one very important detail. The <code>PSObject</code> that I'm testing against is a remote object thus the <code>BaseObject</code> type is named <code>Deserialized.ClassXyz</code>. This is why I'm seeing such strange behavior. </p>