Add-SSPFilesToTemplate.ps1

<#
    .Synopsis
    Adds files from a List on the source to a PnP Template file
    .Description
    This CmdLet add all the files in a particular list to a PnP Template File.
    .Parameter Path
    This parameter contains path of the PnP Template File.
    .Parameter List
    This parameter contains the name of the list from which to add the files from the tenant/site.
    .Parameter Connection
    This parameter provides the context for the call. The default is the current connection
    returned by "Get-PnPConnection".
    .Example
        PS> Add-SSPFilesToTemplate -Path "/tmp/template.pnp" -List "Documents"
    .Example
        PS> Add-SSPFilesToTemplate -Path "/tmp/template.pnp" -List "Documents" -Connection $srcConn
#>


function Add-SSPFilesToTemplate
{
    param(
        [string] $path,
        [string] $list,
        $connection = (Get-PnPConnection)
    )
    $docs = Get-PnPListItem -List $list | Where-Object { $_["FileLeafRef"] -like "*.*" } | ForEach-Object { $_["FileRef"] }
    $docs | ForEach-Object { Add-PnPFileToSiteTemplate -Path $path -SourceUrl $_ }
    return $docs
}