Monthly Archives: January 2015

List length and bitrate for mp3 files using Shell.Application

I recently got the request how to list the Bit Rate and Length for mp3 files. These properties are not available when using the Get-ChildItem cmdlet, but can be revealed when using the Shell.Application ComObject.

$com = (New-Object -ComObject Shell.Application).NameSpace('C:\Music')
# Determine correct index for Bitrate and Length, change names based on installed locale on your system
for( $index = 0; ((-not $bitrateAttribute) -or (-not $lengthattribute)); ++$index ) {
 $name = $com.GetDetailsOf($com.Items,$index)
 if ($name -eq 'Length') {$lengthattribute = $index}
 if ($name -eq 'Bit rate') {$bitrateAttribute = $index}
}
$com.Items() | ForEach-Object {
 # Create custom objects so output can be manipulated easier, also allows for structered output
 New-Object -TypeName PSCustomObject -Property @{
 Name = $_.Name
 Size = $com.GetDetailsOf($_, 1)
 DateCreated = $com.GetDetailsOf($_, 4)
 Length = $com.GetDetailsOf($_,$lengthattribute)
 BitRate = $com.GetDetailsOf($_,$bitrateAttribute)
 } | Select-Object -Property Name,Size,DateCreated,Length,BitRate
}

Now the downside of using the Shell.Application object is that the index number for the attributes can be different in between language packs and Windows versions. The code here has been verified to work on En-Us but for other locales changes to the code will have to be made.

For more information in regards to the Shell.Application object please refer to the following MSDN article:
Shell.Application 

Share