Friday, September 25, 2015

Find files with same content using powershell


Today I needed to find files with identical content within a folder. Inspired by a few examples out there I came up with this (will Work from ps 4.0):

Get-ChildItem|where { ! $_.PSIsContainer }|
Get-FileHash|Group-Object Hash|where{$_.Count -gt 1}|
foreach{write-host "-----------------------------------------------";$_.Group.Path}

Once again, the power of powershell proved itself, as I managed to get it right in less that 10 minutes

For reference:

Group-Object
Get-FileHash