Get-SSPSiteTemplate.ps1

<#
    .Synopsis
    Copies a source site as a template and stores it in the supplied file.
    .Description
    This CmdLet gets a SiteTemplate from the source creates the file. This is meant to
    be used with Invoke-SSPSiteTemplate.
    .Parameter fileName
    This parameter contains a fileName for the template.
    .Parameter Src
    This parameter contains the Url of the source site.
    .Parameter SrcConnection
    This parameter contains the connection context for the source site. The default is the current connection
    returned by "Get-PnPConnection".
    .Parameter Handlers
    This parameter contains a list of the handlers to invoke for the template.
    .Return
    This cmdlet returns the fileName used.
#>


function Get-SSPSiteTemplate {
    param(
        $fileName = "$env:TEMP/SSPSite-$(Get-Random).pnp",
        $srcConnection = (Get-PnPConnection),
        [string[]] $handlers
    )
    rm -f $fileName
    if ($handlers)
    {
        $ignore = Get-PnPSiteTemplate -Out $fileName -Handlers $handlers -IncludeAllClientSidePages -Connection $srcConnection
    } else {
        $ignore = Get-PnPSiteTemplate -Out $fileName -IncludeAllClientSidePages -Connection $srcConnection
    }
    return $fileName
}