Skip to content

Instantly share code, notes, and snippets.

@jamesmanning
Created June 9, 2012 17:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmanning/2901813 to your computer and use it in GitHub Desktop.
Save jamesmanning/2901813 to your computer and use it in GitHub Desktop.
PowerShell script to remove dead entries from the iTunes library
# get reference to the running iTunes
$itunes = New-Object -ComObject iTunes.application
# get all tracks in the entire library
$allTracks = $itunes.LibraryPlaylist.Tracks
# find the entries that are no longer on disk
# NOTE: the API returns the location as null for those, so we check for
# that instead of doing our own filtering based on test-path or similar
$deadEntries = $allTracks | ?{ $_.Location -eq $null }
# now that we know which entries are invalid, delete them from the library
$deadEntries | %{ $_.Delete() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment