One response to “Editing Media Tags from PowerShell”

  1. Zack

    I had a bunch of mp3 files that did not have the artist or song title marked on the file (correctly). All the file names came over CollectionTrack#-Artist-SongTile (eq: 001 – Led Zeppelin – Stairway To Heaven). Here is the code that I used to label this files correctly. This would have a problem for files that have “-” somewhere in the artist or song title. But it worked well enough.

    [Reflection.Assembly]::Load(“taglib-sharp, Version=2.0.3.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0”)
    cd F:\Music\500Rock
    foreach ($f in dir)
    {
    $media = [TagLib.File]::Create(“F:\Music\500Rock\” + $f.ToString())
    $newName = $f.Name
    $splitName = $newName.Split(”-”)

    $i = 1

    foreach($p in $splitName)
    {
    switch ($i)
    {
    2{$media.Tag.Performers= $p.ToString()}
    3{$media.Tag.Title= $p.ToString()}
    }
    $i++
    }
    $media.Tag.Album = “”
    $media.Save()
    Rename-Item $f -NewName ($splitName2.ToString())
    }