Menu Home

Use Powershell to Edit MP3 Tags

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.

** Updated 02/03/2022 with new DLL name and project location **

Categories: Scripting Tech Soup

Tagged as:

Rick Gouin

7 replies

  1. The DLL name seems to have changed in the latest iteration. It’s now simply taglib.dll – change line 14 to match…

  2. Hi Rick,

    I followed your instructions step by step:

    “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.”

    Powershell complained:

    Exception callin “LoadFrom” with 1 Argument(s): “File or Assembly “file:///C:\temp\taglib\taglib.dll” or a dependency was not found. In Modul was a Assemblymanifest expected.”
    In Zeile:14 Zeichen:1
    + [Reflection.Assembly]::LoadFrom(“C:\temp\taglib\taglib.dll”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : BadImageFormatException

    What’s my fault?

    Thanks a lot

  3. Thank you for an interesting article and potentially useful script, Rick.

    When I tried I ran into the same problem as Joerg. The dll file I found under the link you gave was

    taglib.dll 290 816 2005.07.22 00:05 -a–
    which I unpacked from
    d:\Data\Audio\!Data_Management\PShell\taglib-1.3.1-bin.zip 823 108 2023.11.30 17:44 -a–
    The zip also contained a debug version (taglib_d.dll) which I tried using, to no avail.

    @Joerg: Did you get any further?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.