Over the past couple of years I travel quite a lot. As such, I tend to load up on CDs in digital format. However, some of my older files have some nasty names or bad quality.
This has led to me to start grooming my 15,000+ song catalog. That number does not include another 15,000+ audio book files. I love to listen to books while running.
As I was going through the folders of CD rips, iTunes purchases, and other sundry file droppings… I was feeling a bit overwhelmed.
Trying to scope the issue I went for the following categories
- ITunes Music
- Files below a certain Bitrate Threshold
- Artists I did not enjoy
- CD Tagging
Today I am going to talk about how I used PowerShell to identify files below a certain bitrate threshold. Example, I want to get all MP3 files with a bit rate less than or equal to 100. Then I want to delete them… as they sound even worse on digital players (like the iPhone)
- Run the PowerShell Function Get-Mp3FilesLessThan with up to three inputs
- Inputs
- Directory
- BitRate
- File Extension
- Example
- Get-Mp3FilesLessThan \\Server\Music 100 *.mp3 | Format-Wide
- Output
- List of all files where criteria are matched
- Inputs
- Delete result site
- Get-Mp3FilesLessThan \\Server\Music100 *.mp3 | Remove-Item -WhatIf
- I like using –WhatIf because Remove-Item by default does not show results
- Remove the –WhatIf to commit the change
- Get-Mp3FilesLessThan \\Server\Music100 *.mp3 | Remove-Item -WhatIf
Enjoy!
function Get-Mp3FilesLessThan( [string]$directory = "$pwd", [int]$minimumBitrate = 32, [string]$FileTypeExt = "*.mp3" ) {
$shellObject = New-Object -ComObject Shell.Application
$bitrateAttribute = 0
# Find all mp3 files under the given directory
$mp3Files = Get-ChildItem $directory -recurse -filter $FileTypeExt
foreach( $file in $mp3Files ) {
# Get a shell object to retrieve file metadata.
$directoryObject = $shellObject.NameSpace( $file.Directory.FullName )
$fileObject = $directoryObject.ParseName( $file.Name )
# Find the index of the bit rate attribute, if necessary.
for( $index = 5; -not $bitrateAttribute; ++$index ) {
$name = $directoryObject.GetDetailsOf( $directoryObject.Items, $index )
if( $name -eq 'Bit rate' ) { $bitrateAttribute = $index }
}
# Get the bit rate of the file.
$bitrateString = $directoryObject.GetDetailsOf( $fileObject, $bitrateAttribute )
if( $bitrateString -match '\d+' ) { [int]$bitrate = $matches[0] }
else { $bitrate = -1 }
# If the file has less than or equal to the desired bit rate, include it in the results.
if( $bitrate -le $minimumBitrate ) { $file }
}
}

Robert Wood: Ryan, you are saying the ping uses the FQDN?, because the only way it ...
Ryan Ephgrave: Are you talking about the WOL tool? I only check for the IP when I hav...
Robert Wood: Hi we have right click tools installed with SCCM 2012, I have noticed...
Garth Jones: Wow that is cool thanks!!...
Garth Jones: Wow that is cool thanks!!...