Compare-Object Powershell to validate a folder copy

06 June,2012 by Jack Vamvas

Question: As part of a nightly ETL process , a bunch of folders\files are copied from one location to another. The contents of the folders are processed via a SSIS job. How can I validate the copy is successful?

Answer: Compare-Object Powershell can compare the contents of the folder and report on differences.  Build in a compare step before the SSIS process step . If there are differences after the copy , trap the error and log the difference

The Compare-Object cmdlet compares two sets of objects i.e Reference Set and Difference Set

 

 

copy .\difftest1\* .\difftest2$dir1 = Get-ChildItem .\difftest1 -Recurse$dir2 = Get-ChildItem .\difftest2 -RecurseCompare-Object $dir1 $dir2 -IncludeEqual$diff = Compare-Object $dir1 $dir2if($diff){        "WARNING: There are differences between the source and target folders"}else{   "SUCCESS:The folder contents copied successfully"}

Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Compare-Object Powershell to validate a folder copy


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer