Skip to content

Instantly share code, notes, and snippets.

@jackgill
Created May 6, 2014 04:01
Show Gist options
  • Save jackgill/12afe3167f2dff4e4032 to your computer and use it in GitHub Desktop.
Save jackgill/12afe3167f2dff4e4032 to your computer and use it in GitHub Desktop.
DeDup-iTunes.ps1
<#
.SYNOPSIS
Finds duplicate iTunes tracks, and if the -Delete parameter is specified, deletes them.
.PARAMETER Delete
Delete duplicate tracks
#>
[CmdletBinding()]
param(
[switch] $Delete
)
$itunes = New-Object -com itunes.application
$tracks=$itunes.LibraryPlaylist.Tracks
$seen = @{}
foreach ($track in $tracks) {
if (-not $track.Location) {
continue
}
if ($seen.ContainsKey($track.Location)) {
$track.Location
if ($Delete) {
$track.Delete()
}
}
else {
$seen.Set_Item($track.Location, $True)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment