Thanks for that link. I took it, sped it up, and updated it for PowerShell v2.



Param (

       [string] $Path = (Get-Location),

       [Switch] $ShowDuplicates

)



$script:cryptoServiceProvider = 
[System.Security.Cryptography.MD5CryptoServiceProvider]

$script:hashAlgorithm = New-Object $script:cryptoServiceProvider



function Get-MD5

{

       Param (

              [System.IO.FileInfo] $file = $(throw 'Usage: Get-MD5 
[System.IO.FileInfo]')

       )



       # This Get-MD5 function sourced from:

       # http://blogs.msdn.com/powershell/archive/2006/04/25/583225.aspx

       # Updated for PowerShell v2.0.



       try

       {

              $stream = $file.OpenRead()

              $hashByteArray = $script:hashAlgorithm.ComputeHash( $stream )

       }

       finally

       {

              if( $stream )

              {

                     $stream.Close()

              }

       }



       return [string]$hashByteArray

}



if( 1 )

{

       $directoryInfo = New-Object System.IO.DirectoryInfo( $Path )



       $fileGroups    = $directoryInfo.GetFiles( '*', 'AllDirectories' )       |

                     ? { $_.Length -gt 0 } |

                     group Length          |

                     ? { $_.Count -gt 1 }

}

else

{

       $fileGroups = Get-ChildItem $Path -Recurse |

              Where-Object { $_.Length -gt 0 }   |

              Group-Object Length                |

              Where-Object { $_.Count -gt 1 }

}



$results = @()



foreach ($fileGroup in $fileGroups)

{

       foreach ($file in $fileGroup.Group)

       {

              Add-Member NoteProperty ContentHash (Get-MD5 $file) -InputObject 
$file

       }



       $result = $fileGroup.Group |

              Group-Object ContentHash |

              Where-Object { $_.Count -gt 1 }

       if( $result )

       {

              $results += $result

       }

}



if( $filegroups -and $fileGroups.Count -and ( $fileGroups.Count -gt 0 ) )

{

       write-host "Total filegroups = $($fileGroups.Count)"

}



if( $ShowDuplicates )

{

       foreach( $entry in $results )

       {

              if( $entry.Count -gt 1 )

              {

                     foreach( $item in $entry.Group )

                     {

                           $item.Fullname



                     }

                     " "

              }

       }

}

else

{

       $results

}



$results       = $null

$filegroups    = $null

$directoryInfo = $null



$script:hashAlgorithm         = $null

$script:cryptoServiceProvider = $null





Regards,



Michael B. Smith

Consultant and Exchange MVP

http://TheEssentialExchange.com





-----Original Message-----
From: Kurt Buff [mailto:[email protected]]
Sent: Wednesday, August 03, 2011 1:34 PM
To: NT System Admin Issues
Subject: Re: find duplicate files



Try this, among others:

http://blog.codeassassin.com/2007/10/13/find-duplicate-files-with-powershell/



Kurt



On Wed, Aug 3, 2011 at 08:47, Bill Humphries 
<[email protected]<mailto:[email protected]>> wrote:

> Hi all,

>

> Any suggestions for a tool that I could use to search for duplicate files on

> a 20tb Xsan?  Although it primarily has Macs attached to it, I do have one

> windows machine.

>

> Thanks.

>

> Bill

>

> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~

> ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

>

> ---

> To manage subscriptions click here:

> http://lyris.sunbelt-software.com/read/my_forums/

> or send an email to 
> [email protected]<mailto:[email protected]>

> with the body: unsubscribe ntsysadmin

>



~ Finally, powerful endpoint security that ISN'T a resource hog! ~

~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~



---

To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/

or send an email to 
[email protected]<mailto:[email protected]>

with the body: unsubscribe ntsysadmin



~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to