PowerShell – Having fun with Compare-Object in the 2012 Scripting Games

This year I was competing in the Windows PowerShell Scripting Games 2012.
One of the exercises in the Beginners class was to compare two folders.
Ed Wilson (Microsoft ScriptingGuy) provided a script to create two folders with a bunch of files in them and delete one file from each folder.

So, I started to script… by using the Compare-Object cmdlet. This lets you compare objects (sounds kinda logical when looking at the name of the cmdlet, right? ).

But, then there was the Expert Commentary… here the expert provided explanation of the exercise and the solution. The solution he provided was as follows:

One comment

Compare-Object is a great cmdlet and very useful. But there are some gotchas when using it with certain objects. I wrote an article a while back that takes a look at one of those gotchas with comparing objects and not getting the results that one might think they would get. http://learn-powershell.net/2012/01/02/compare-object-weirdness-or-business-as-usual/
Good job on this article and great job in the Scripting Games this year!