Duplicate File Finder Script

I’ve been trying to cleanup my Plex Library, and since I’m retrieving videos from a couple sources like TiVo and DVDs, I’m undoubtedly encountering doubles.  Now, there are handful of issues you run into like ignoring case and file extension.

Used Get-Duplicate Method from here 

Function Get-Duplicate {
    param($array, [switch]$count)
    begin {
        $hash = @{}
    }
    process {
        $array | %{ $hash[$_] = $hash[$_] + 1 }
        if($count) {
            $hash.GetEnumerator() | ?{$_.value -gt 1} | %{
                New-Object PSObject -Property @{
                    Value = $_.key
                    Count = $_.value
                }
            }
        }
        else {
            $hash.GetEnumerator() | ?{$_.value -gt 1} | %{$_.key}
        }
    }
}

Function Show-Duplicates{
	param($drive)
	begin {
			$duplicates = Get-Duplicate (Get-ChildItem $drive
| Foreach-Object {$_.BaseName}).ToLower() | Sort-Object

			if($duplicates.Length -eq 0)
			{
				Write-Host "No Duplicates"
			}
			else
			{
				$duplicates | Sort-Object
			}
		}
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s