Looking for a PowerShell script to compare two folders recursively

Tag: powershell Author: cuizhen0123 Date: 2009-09-13

Just thought it would be nice to have one but my PS skills are not up to task. Anybody can share theirs?

Best Answer

Easy enough to do something simple:

$d1 = get-childitem -path $dir1 -recurse
$d2 = get-childitem -path $dir2 -recurse
compare-object $d1 $d2

More sophistication required depending on the definition of difference.

comments:

This works... Is it possible to include relative path into comparision results, as well as some output while this is processing?
Figued it out - add -name to each of get-childitem, you'll get necessary results faster and you'll see the progress
'-name' is a new one for me :-), I'll have to remember that.
Is there any easy way to get this method to compare the contents of the files?
@Fopedush Compare-Object compares collections of objects. If they are two sets of strings that are the contents of two files, then the files' contents are compared.