powershell - Serializing PsObject for Invoke-Command -
i'm looking best or proper way pass psobject remote function invoke-command. convertto-xml serializing there no built-in reverse cmdlet. solutions i've found online content specific.
i implemented following functions works few objects tested seems rather hacky. going bite me? there better, yet still simple solution?
function get-tmpfilename () {...} function serialize-psobject($obj) { $tmpfile = get-tmpfilename export-clixml -inputobject $obj -path $tmpfile $serializedobj = get-content $tmpfile remove-item $tmpfile $serializedobj } function deserialize-psobject($obj) { $tmpfile = get-tmpfilename $obj > $tmpfile $deserializedobj = import-clixml $tmpfile remove-item $tmpfile $deserializedobj }
are aware powershell serializes objects sent through invoke-command
?
if reason isn't enough or isn't working you, can use use built-in serialization directly:
$clixml = [system.management.automation.psserializer]::serialize($object) $object = [system.management.automation.psserializer]::deserialize($clixml)
.serialize
has overload can specify depth (for objects within objects).
these same methods used in implementing export-clixml
, import-clixml
(but cmdlets work directly files , not strings).
Comments
Post a Comment