Accessing Audio File Metadata

Ray T 1 Reputation point
2021-12-08T07:40:22.833+00:00

Is there a way to read/write audio file (mp3, flac, wav) metadata using Microsoft PowerShell? I just need a dll with this functionality so that I can call the functions from within the PowerShell script.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,580 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 47,471 Reputation points
    2021-12-08T16:21:00.447+00:00

    I plagiarized this code and updated it a little bit. The original code is here: mp3-tag

    Function Get-MP3MetaData {
        [CmdletBinding()]
        [Alias()]
        [OutputType([Psobject])]
        Param
        (
            [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
            [String] $Directory
        )
    
        Begin {
            $shell = New-Object -ComObject "Shell.Application"
            $PropertArray = 0, 1, 2, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 27, 28, 36, 220, 223
        }
        Process {
            Foreach ($Dir in $Directory) {
                $ObjDir = $shell.NameSpace($Dir)
                $SearchDir = $Dir + "\*"                # when Get-ChildItem uses -Include the Path must end with *
                Get-ChildItem $SearchDir -File -Include *.mp3,*.mp4 |
                    ForEach-Object{
                        $ObjFile = $ObjDir.parsename($_.Name)
                        $MetaData = [ordered]@{}
                        Foreach ($item in $PropertArray) { 
                            If ($ObjDir.GetDetailsOf($ObjFile, $item)) { #To avoid empty values
                                $MetaData[$($ObjDir.GetDetailsOf($MP3, $item))] = $ObjDir.GetDetailsOf($ObjFile, $item)
                            }
                        }
                        $MetaData['Directory'] = $Dir
                        $MetaData['Fullname'] = (Join-Path $Dir $_.Name -Resolve)
                        $MetaData['Extension'] = $_.Extension
                        [PSCustomObject]$MetaData
                    }
            }
        }
        End {
        }
    }
    
    # Example of how to use the function:
    #ForEach($item in ("D:\Powershell\Tutorials\4_DSC" |Get-MP3MetaData)){
    #    $NewName = [regex]::Replace($(($item.Title).Split(":")[1].Trim() + $item.extension),"[*(/)\\&#]",{''})
    #    $Oldname = $item.Fullname
    #    Rename-Item -LiteralPath $item.Fullname -NewName $NewName -Force
    #}
    
    0 comments No comments

  2. Limitless Technology 39,736 Reputation points
    2021-12-10T08:54:44.917+00:00

    Hello

    Thank you for your question and reaching out.

    Yes , it is possible to get Audio files metadata using PowerShell.
    Please have a look on below Microsoft article.

    https://devblogs.microsoft.com/scripting/list-music-file-metadata-in-a-csv-and-open-in-excel-with-powershell/


    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

  3. MadMat 1 Reputation point
    2022-12-13T17:11:15.477+00:00

    Hi...
    Thanks for the post but for me it produced millions of errors.
    Any ideas?
    I changed the path to my mp3 files as shown

    thanks

    ==================

    PS D:\Videos\downloaded\test> ForEach($item in ("D:\Videos\downloaded\test" |Get-MP3MetaData)){

    > $NewName = [regex]::Replace($(($item.Title).Split(":")[1].Trim() + $item.extension),"[*(/)\&#]",{''})
    > $Oldname = $item.Fullname
    > Rename-Item -LiteralPath $item.Fullname -NewName $NewName -Force
    > }

    You cannot call a method on a null-valued expression.
    At line:2 char:31

    • ... ::Replace($(($item.Title).Split(":")[1].Trim() + $item.extension),"[* ...
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

    Exception calling "Replace" with "3" argument(s): "Value cannot be null.
    Parameter name: input"
    At line:2 char:31

    • ... ::Replace($(($item.Title).Split(":")[1].Trim() + $item.extension),"[* ...
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : ArgumentNullException

    Rename-Item : Cannot bind argument to parameter 'NewName' because it is null.
    At line:4 char:50

    • Rename-Item -LiteralPath $item.Fullname -NewName $NewName -Force
    • ~~~~~~~~
    • CategoryInfo : InvalidData: (:) [Rename-Item], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RenameItemCommand
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.