Deleting missing or dead iTunes music entries

The song could not be used because the original file could not be found.  Would you like to locate it?

For whatever reason, I ended up deleting some MP3 files from my music storage, and my iTunes Library still had (now "dead") links to the files.

To find these dead links I wrote some Powershell code …

$itunes = $null
$lTotal_iTunes_Tracks = 0
$i = 0    

# Test that we have launched iTunes Application
try {
    $itunes = New-Object  -ComObject iTunes.Application
catch {
Write-Warning $_

$lTotal_iTunes_Tracks = $itunes.LibraryPlaylist.Tracks.Count

for($i = 1; $i -le $lTotal_iTunes_Tracks; $i++)
    if ($itunes.LibraryPlaylist.Tracks.Item($i).Kind -eq 1) {
        if ($itunes.LibraryPlaylist.Tracks.Item($i).Location -eq $null) {
            if ($itunes.LibraryPlaylist.Tracks.Item($i).Location -eq $null) {
                Write-Output $itunes.LibraryPlaylist.Tracks.Item($i).Name  

The code outputs the Track name.

I noticed something strange though. 
iTunes tries to fix the link when you select "Song info" in iTunes.  If it can’t, it throws the error in the screenshot above.

Why is that important to know?
Well, in the script I could delete the Track if it had an empty Location.  If I did that, I could be preventing iTunes from the chance of finding the Track itself.

So I didn’t.

I went looking for a way to trigger that iTunes "fix" process.  I could not find it.  In the typical case of "It’s easy when you know the answer to find the answer." I found Steve MacGuire’s iTunes For Windows Scripts page, which has 120+ useful scripts on it.

Other references
Samuel Wood’s (aka Otto) RemoveDeadTracks script
How to Easily Remove Duplicate Tracks on iTunes [Windows]