public/Convert-MediaFile.ps1

function Convert-MediaFile {
    <#
        .EXAMPLE
            Convert-MediaFile -Path C:\media
         
    #>

    [CmdletBinding()]
    param(  

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Path

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            $PathExists = Test-Path -Path $Path

            if ($PathExists) {
                
                Set-Location -Path $Path
                $FilesToProcess = Get-ChildItem -Path $Path -File -Filter '*.png' -ErrorAction Stop

                foreach ($File in $FilesToProcess) {

                    $CurrentName = $($File.FullName)
                    $NewName = $CurrentName.Replace('.png','.jpg')

                    # third party application to conver
                    magick $CurrentName $NewName

                } # foreach

            } # if

        }
        catch {

            throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message"

        } # try catch

    } # process

} # function