Q. How can I use Windows PowerShell to update a file's media tags?

John Savill

May 13, 2008

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A. When I recently reviewed my music library, I found I had a lot of music videos, which I'd used the naming format -.wmv. I also found that the files' media tags were blank, so if I tried to view the videos with Windows Media Player (WMP), I would just see blank names. I wanted to automate the media tag population in PowerShell through the filename but couldn't work out how to update the title and performer media tags.

Then I ran across a tag library at developer.novell.com/wiki/index.php/TagLib_Sharp that allows access to various languages' media tags. I downloaded the tag library and saved it to my computer. Then I wrote the code

[Reflection.Assembly]::LoadFile("D:Programstaglib-sharp-1.9.75474-net20Releasetaglib-sharp.dll")
cd "D:MultimediaFilmMusic Videos"
foreach ($f in dir)
{
$mediafile = [TagLib.File]::Create(“D:MultimediaFilmMusic Videos” + $f.ToString())
$splitName = $f.Name.Split(”-.")
write-host $splitname[0] $splitname[1]
$mediafile.Tag.Title = $splitname[0] + "-" + $splitname[1]
$mediafile.Tag.Performers = $splitname[0]
$mediafile.Save()
}

to parse my music-video folder files and populate the tags accordingly. Obviously, you can change how the script works and what it populates, but this script will give you a good start. You need to modify the script's first line (at minimum) to show where you saved the taglib DLL.

Once I executed the script, all my media files' title and performer tags were populated.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like