If you have thousands of duplicate songs in iTunes on Windows—especially **iCloud Music Library / Apple Music** tracks that aren't downloaded locally—cleaning them up manually is painful, and standard COM deletion scripts usually stall because iTunes throws a modal confirmation popup for every single cloud track (or fails with `AddTrack()` on non-downloaded items).
I put together a lightweight, two-step PowerShell script (`Remove-iTunesDuplicates.ps1`) that solves both issues safely without requiring any third-party software:
### How It Works
- **Step 1 — Dry Run (CSV Preview):** Runs `.\Remove-iTunesDuplicates.ps1` to scan your Music library (matching normalized **Song Name + Artist + Album** while ignoring 1–2 second duration differences) and exports `iTunes_Duplicates_Preview.csv` to your Desktop without changing anything.
- **Step 2 — Tag & Batch Delete via Smart Playlist:** Once you're happy with the CSV, run `.\Remove-iTunesDuplicates.ps1 -TagDuplicates`. Instead of triggering hundreds of individual deletion popups, it appends `DELETE_DUPLICATE` to the **Grouping** field of each duplicate track.
- **One-Click Cleanup in iTunes:** Create a Smart Playlist matching **`Grouping` contains `DELETE_DUPLICATE`**, press **`Ctrl + A`**, and hit **`Shift + Delete`** once to remove the entire batch from iTunes and iCloud.
*(I just used this on my own ~7,500-song iCloud library and cleanly removed over 3,200 duplicates in minutes.)*
### Quick Notes Before Running
* Requires the **standalone desktop version** of iTunes for Windows (not the Microsoft Store app, which lacks COM support).
* Run PowerShell as a **standard user** (not Administrator) to avoid Windows COM privilege mismatch errors (`0x80080005`).
**Download the script & full instructions here:**
Hope this saves someone else a few hours of manual clicking!