Copy-SSPSite.ps1

<#
    .Synopsis
    Copies a source site as a template and instantiates it at the destination.
    .Description
    This CmdLet gets a SiteTemplate from the source and instantiates it at the
    destination url. It attempts to download image files from the source in
    the Site Assets folder and upload them to the destination site.
    .Parameter Src
    This parameter contains the Url of the source site.
    .Parameter Dest
    This parameter contains the Url of the destination site.
    .Parameter SrcConnection
    This parameter contains the connection context for the source site. The default is the current connection
    returned by "Get-PnPConnection".
    .Parameter DestConnection
    This parameter contains the connection context for the destination 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.
 #>

#>

function Copy-SSPSite {
    param(
        $srcConnection = (Get-PnPConnection),
        $destConnection = (Get-PnPConnection),
        [string[]] $handlers
    )
    $file = "$env:TEMP/SSPSite-$(Get-Random).pnp"
    Remove-Item $file -Force
    if ($handlers)
    {
        $ignore = Get-PnPSiteTemplate -Out $file -Handlers $handlers -IncludeAllClientSidePages -Connection $srcConnection
    } else {
        $ignore = Get-PnPSiteTemplate -Out $file -IncludeAllClientSidePages -Connection $srcConnection
    }

    if ($handlers)
    {
        $ignore = Invoke-PnPSiteTemplate -Path $file -Handlers $handlers -Connection $destConnection
    } else {
        $ignore = Invoke-PnPSiteTemplate -Path $file -Connection $destConnection
    }
}