Uncompressing Serialized Data

by Nov 9, 2017

In the previous tip you learned how you can use Export-CliXml to serialize data and then use Compress-Archive to shrink the huge XML files to only a fraction of original size.

Today, we do the opposite: we take a ZIP file that contains XML serialization data, and restore (“rehydrate”) the serialized objects. This of course assumes you created such a file with yesterday’s tip.

# path to existing ZIP file $ZipPath = "$env:TEMP\data1.zip" # by convention, XML file inside the ZIP file has the same name $Path = [IO.Path]::ChangeExtension($ZipPath, ".xml") # expand ZIP file Expand-Archive -Path $ZipPath -DestinationPath $env:temp -Force # deserialize objects $objects = Import-Clixml -Path $Path # remove XML file again Remove-Item -Path $Path -Recurse -Force $objects | Out-GridView 

Twitter This Tip! ReTweet this Tip!