Get-SSPFiles.ps1

<#
    .Synopsis
    Finds the names of all the files in a folder that match.
    .Description
    This CmdLet downloads all the files that match the matches in a particular folder.
    .Parameter Matches
    This parameter contains list of string matches.
    .Parameter Path
    This parameter contains path in which to download the files on your local machine.
    .Parameter Connection
    This parameter provides the context for the call. The default is the current connection
    returned by "Get-PnPConnection".
    .Example
        PS> Get-SSPFile -Matches ("*.png", "*.jpg") -Folder "SiteAssets" -Path "."
#>


function Get-SSPFiles {
    param(
        [string] $folder,
        [string[]] $matches = @("*"),
        [string] $path,
        $connection = (Get-PnPConnection)
    )
    $files = Find-SSPFiles -Matches $matches -Folder $folder -Connection $connection
    $fileNames = @()
    if ($files) {
        # Only get the top level files, no sub folders
        foreach ($f in $files) {
            if ($f.ServerRelativeUrl -and (-not ($f.ServerRelativeUrl -match "$($folder)/.*/")))
            {
                Write-Host Downloading $f.ServerRelativeUrl as $f.Name
                Get-PnPFile -Url $f.ServerRelativeUrl -AsFile -Path "$path" -FileName $f.Name -Force -Connection $connection
                $fileNames += $f.Name
            }
        }
    }
    return $fileNames
}