Use Powershell to Edit MP3 Tags

Posted in Scripting, Tech Soup6 years ago • Written by Rick Gouin2 Comments

PowerShell LogoHere is a bit of a change from the usual datacenter type posts. A nameless friend of mine recently plugged her Ipod into a different PC that was set to auto-sync. It appeared to erase all of her MP3s from her Ipod without prompting or intervention.  I am not familiar with iTunes, iPods, or any Apple products, but a quick search suggested this was a common occurrence.  There are even a few software packages out there to recover the information, as the files don’t actually get deleted.  It seems just some meta data gets removed.  After running one such software package, all the MP3s were recovered, but some of them had weird file names or were missing various tag attributes. I tried using common MP3 tag editing software, such as MP3Tag, but found that I needed some logic to get everything squared away. I wrote a quick and dirty powershell script to standardize the filenames and tag information, based on which attributes were still present. Script is below.

As I continued to look through these files, I’d find different scenarios in the files that I needed to account for in the script.  For example, a question mark (?) is OK to have in an MP3 tag, but not in a filename.  As I went, I added these scenarios. The result is a procedural script to get the job done.

Now, you may not be solving the exact same problem that I was, but in this script, we show how to load an external .DLL in powershell, how to get and set MP3 tags with it, how to rename files, how to strip out illegal file characters and more!  Lots of good stuff in here.  It should make a pretty good starting point for any MP3 organization issue you need to sort out.

First, you”ll need the Taglib mp3 editing library.  You can download that here.  Just grab the .dll file and put it in the same directory that you run your powershell script from.

Next, grab the script from below.

Finally, at the top of the script, add the path to your MP3 files that you need to edit. After you run this script, your MP3 files will get renamed like so: “Artist Name-Song Title.mp3”. The tags will also be updated to match.

Lets give credit where credit is due! I got the basics for this script from this blog post. Was this script useful to you? Have any other scenarios you would like to see handled by the script? Any issues running it? Let me know in the comments below.

TAGS:

2 Comments so far. Feel free to join this conversation.

  1. goyete July 14, 2016 at 4:57 am - Reply

    You need admin properties to “LoadFrom”…
    😉

  2. ligg October 11, 2020 at 7:29 pm - Reply

    Just starting to use PS. Exactly what I was looking for. Thank you.

Leave A Response