Comparing Folder Content

by Apr 13, 2015

To quickly compare folder content and find out files that exist only in one of two folders, try this example:

$list1 = Get-ChildItem c:\Windows\system32 | Sort-Object -Property Name

$list2 = Get-ChildItem \\server12\c$\windows\system32 | Sort-Object -Property Name

Compare-Object -ReferenceObject $list1 -DifferenceObject $list2 -Property Name | 
  Sort-Object -Property Name

Here, the script takes two folder listings, one from the local machine, and another one from a remote computer. Compare-Object then identifies the files that only exist in one of the two lists.

Twitter This Tip! ReTweet this Tip!