Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell - Compare Folder Contents

I have the below code which compares the two folders and outputs the files different with respect to each folder, is there a way to get this to output the full file/folder path for files in subfolders?

Cheers

 # Create varaibles to store folder paths - pass to Strings... 
 param([string]$argFolderA,[string]$argFolderB)

 # Set variables for folder
 $FolderA = Get-ChildItem -Recurse -path $argFolderA
 $FolderB = Get-ChildItem -Recurse -path $argFolderB

 # Compare the contents and output the files different within each folder. 
 Compare-Object -ReferenceObject $FolderA -DifferenceObject $FolderB >> C:\CmpOut.txt
like image 817
PnP Avatar asked Jan 14 '13 14:01

PnP


1 Answers

Use the Passthru flag of the Comapre-Object like so:

Compare-Object -ReferenceObject $FolderA -DifferenceObject $FolderB -Passthru | % {$_.FullName}  >> C:\CmpOut.txt
like image 111
Dave Sexton Avatar answered Sep 21 '22 12:09

Dave Sexton