O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.10. Detecting Changes and Differences Among Objects

All scripting, sooner or later, will hit the task of comparing two objects or collections, trying to find what has been added or deleted. Compare-Object is our friend here: it knows how to loop over two objects, the reference object and another one, and report on their differences. Traditional diff tools work on text only, while Compare-Object works on real objects. Here is how we can use it to detect the changes between two folders: the current one and yesterday's backup:

PS> diff (dir PowerShellBackup) (dir PowerShell)

InputObject                           SideIndicator
-----------                           -------------
kill.log                              =>

The => side indicator means that the kill.log object is present in the right-hand collection, the difference ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required