Wednesday, 15 June 2016

Compare two folder's with PowerShell

Below code is the example of how to compare two folder's with PowerShell. This will help us to know what all files were changed. This script will differentiate file on the bases of length but user can change the variable according to usage.   



###PowerShell Start 

#### Variables 
$folderReference = "C:\test"
$folderDifference = "D:\TP"


$FolderReferenceContents = Get-ChildItem $folderReference -Recurse |
    where-object {-not $_.PSIsContainer}
$FolderDifferenceContents = Get-ChildItem $folderDifference -Recurse |
    where-object {-not $_.PSIsContainer}

#get only files that are on laptop not on server
Compare-Object -ReferenceObject $FolderReferenceContents `
-DifferenceObject $FolderDifferenceContents -Property ('Name', 'Length') -PassThru |
    where-object { $_.SideIndicator -eq '=>'} |
        select "FullName"


###PowerShell END

No comments:

Post a Comment