Hands up if you’ve tried to compare 2 objects of some type to see what – if any – differences there are between them?
I tried and gave up. PowerShell’s native “Compare-Object” isn’t very helpful. It will tell you IF there’s a difference, but it’s not particularly forthcoming.
Borne of that experience comes “Compare-Objects.ps1”. You might see some similarities here with two of my other scripts (Compare-PkiCertificates & Update-SfbCertificate.ps1) as the comparison engine is essentially the same between them.
Feed this script the “type” of the object and the names of two of them, and it will present a tabular comparison, highlighting all those attributes that differ.
All of these formats are valid input examples:
Compare-Objects.ps1 –type csuser –object1 “greig” –object2 “jessica”
Compare-Objects.ps1 –type csuser –object1 greig –object2 jessica
Compare-Objects.ps1 get-csuser greig jessica
Armed with the above input the script performs two “get-” commands to query the objects, then feeds the results into the differencing engine. The “get-” is implied in the command-line input, and the script will cope fine if you absent-mindedly include it, like in the last example above.
If you’ve already captured the objects, you can feed them to the script and it will compare them directly, skipping the “get” step:
Compare-Objects.ps1 –type $null –object1 $greig –object2 $jessica
Compare-Objects.ps1 $null $greig $jessica
For more information add the “-verbose” switch, and if you don’t want it querying my blog in search of an update, use “-SkipUpdateCheck”.
Continue reading ‘Compare-Objects.ps1’ »