Persisting Comparison Snapshots

by Feb 25, 2009

Whenever you'd like to compare long-time results or compare data on different machines, you want to use persisted result sets. Persisted result sets do not live in memory but are instead written to xml as file. This way, you can collect data from different machines or load snapshot information whenever you need a comparison snapshot.

To create a snapshot as xml file, make sure you use Select-Object and select only those properties that you plan to use for comparisons:

Dir $home | Select-Object Name, Length | Export-Clixml $homebaseline.xml

Later, when you'd like to do comparisons, reload the xml file using Import-CliXML. Make sure both result sets are imported from xml. Never compare a loaded xml file with live data because both are different object types:

Set-Content $hometestfile.txt "Hello World"
# load persisted snapshot:
$shot1 = Import-Clixml $homebaseline.xml
# create new snapshot and convert to xml, then reload:
Dir $home | Select-Object Name, Length | Export-Clixml $hometemp.xml
$shot2 = Import-Clixml $hometemp.xml
# Compare
Compare-Object $shot1 $shot2 -property Name, Length