Diff folders using Powershell or Robocopy

Powershell:

To compare two folders I perform the following steps:

  1. Use the Get-ChildItem cmdlet with the recurse switched parameter and the path parameter (points to the folder to use for reference) to obtain a collection of fileinfo objects. Store these objects in a variable.
  2. Use the Get-ChildItem cmdlet with the recurse switched parameter and the path parameter (points to the folder to use for comparison) to obtain a collection of fileinfo objects. Store these objects in a different variable.
  3. Use the Compare-Object cmdlet and specify the objects stored in the first variable to the ReferenceObject parameter. Supply the objects stored in the second variable to the DifferenceObject parameter.

Note   Do not get hung up on whether the first folder should be the reference object or the difference object. The position of the folder in the two parameters determines the direction of the comparison arrows, but as long as you know which folder is difference or reference, you will be fine.

The code I type on my laptop is shown here:

$fso = Get-ChildItem -Recurse -path C:\fso

$fsoBU = Get-ChildItem -Recurse -path C:\fso_BackUp

Compare-Object -ReferenceObject $fso -DifferenceObject $fsoBU

The code and associated output are shown in the following figure. The output tells me that inputobject (this is the difference object parameter) is missing three files: a.txt, b.txt, and c.txt. I need to copy these three files to the c:\fso_backup folder.

Image of code and associated output

http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/08/easily-compare-two-folders-by-using-powershell.aspx

Robocopy:

Basic comparison of two folders and write a log file listing the differences.

ROBOCOPY “\\FileShare\SourceFolder” “\\FileShare\ComparisonFolder” /e /l /ns /njs /njh /ndl /fp /log:reconcile.txt

http://improvingsoftware.com/2013/09/09/how-to-diff-two-folders-from-a-windows-command-prompt/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s