≡ Menu

Change the track name of music files using PowerShell

I went to my friend room last week to see cricket match. He got a new mobile phone and trying to copy all his favorite songs into it. After copying a few he realized that, file name that appearing his laptop and display name in phone are not same for songs he is copying. He disappointed and figureout that he has o change the title of each song by going to properties of each mp3 file. As I just sitting beside to him, he asked me if I can automate anything there to speed up the process. He has lot of MP3 files in such manner and thought of helping him with my favorite powershell scripting.

I authored a small script, which reads files of given extension type and changes the title of them to file name. So that music players shows the same name when playing…

$files = Get-ChildItem -Filter *.mp3 -Path c:MyMusic -Recurse
$wmp = New-Object -ComObject wmplayer.ocx

foreach ($file in $files) {
	$filename = $file.FullName
	$fileshortname = $file.Name.Split(".")[0]
	$metadata = $wmp.newMedia($filename)
	if ($metadata.name -ne $fileshortname) {
		Write-Host "Setting metadata"
		$metadata.name = $fileshortname

		}
	}

Comments on this entry are closed.

  • Ramesh April 25, 2010, 9:41 pm

    it works…thank you

  • Altair February 23, 2012, 3:06 am

    so how does it work (sorry, new to powershell) should i copy it to my phone or ??

  • G May 9, 2015, 7:36 pm

    Nice solution! Works well.

  • Chris Ross December 3, 2015, 11:20 pm

    Best PoSh script for the day!

  • Benny Hartwig May 25, 2017, 1:21 pm

    Amazing !!