PowerShell: ¿cómo convertir un objeto COM a un tipo de interoperabilidad .NET?
Como se describe en mi preguntaCrear imagen ISO con PowerShell: ¿cómo guardar IStream en un archivo?, en PowerShell creo unIStream
objeto de la siguiente manera:
$is = (New-Object -ComObject IMAPI2FS.MsftFileSystemImage).CreateResultImage().ImageStream
Este objeto es del tipo (PowerShell)System.__ComObject
. Y de alguna manera PowerShell sabe que es unaIStream
:
PS C:\> $is -is [System.Runtime.InteropServices.ComTypes.IConnectionPoint]
False
PS C:\> $is -is [System.Runtime.InteropServices.ComTypes.IStream]
True
Sin embargo, un reparto a este tipo falla:
PS C:\> [System.Runtime.InteropServices.ComTypes.IStream] $is
Cannot convert the "System.__ComObject" value of type "System.__ComObject" to type "System.Runtime.InteropServices.ComT
ypes.IStream".
At line:1 char:54
+ [System.Runtime.InteropServices.ComTypes.IStream] $is <<<<
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
¿Cómo hago que esta conversión funcione, sin usar el código C #?
Actualizar Aparentemente, esta conversión no puede funcionar, como dice la respuesta de x0n.
Ahora, mi objetivo es pasar estaIStream
bjeto @ COM para algún código C # (parte del mismo script de PowerShell que usaAdd-Type
), donde se convertiría en un objeto .NET de tipoSystem.Runtime.InteropServices.ComTypes.IStream
. ¿Es eso posible? Si no, ¿qué alternativas tengo?