Thomas Gass Thomas Gass - 3 years ago 167
C# Question

Access Music File Metadata in Powershell

So over the years between getting copied from one PC/hard drive to the next, my music collection is in a bit of a mess, so I want to go through each one programmatically and update the file metadata in the below screenshot (from right click > Properties on the file):

enter image description here

Some of the files are MP3 so I know ID3 can be used there (I had tried using Get-Content to view the last 128 bytes where the ID3 tags go, but only some small bits show as readable text, assuming this is because it's a binary file and needs decoded/parsed in some specific way). About an equal number are WMA (quite an old codec version, probably 7 or 8) and some are uncompressed WAV.

So I possibly need two things:

a) a way to access and update the ID3 info for the MP3 type files
b) a way to access the File Properties (at the Windows level) for WMA and WAV; if this method would also work for MP3 that'd be fantastic

Anyone got any ideas? I know this is possible in C# but that's a bit over my head right now as more used to scripting. If it needs to be done in a proper compiled program so be it but hoping there's a way to do it in shell.

Answer Source

Download the tagsharp.dll from HERE.

There is a separate module which can be used to modify any of the meta data like:

get-childitem mylocal.mp3 | set-album "MyLocalAlbum"

or something like this :

$files = Get-ChildItem D:\Folder -include *.mp3 -recurse 
[System.Reflection.Assembly]::LoadFile("C:\TagLibDirectory\taglib-sharp.dll" ) 

foreach($iFile in $files) 
    $mediaFile.Tag.Album = $iFile.Directory.Name 

Hope it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download