Add-SSPSiteScript.ps1

<#
    .Synopsis
    Update or Create a Site Script
    .Description
    Creates or Updates an existing Site Script.
    .Parameter Title
    This parameter contains title of the site script. Site scripts are identified by their title.
    .Parameter Description
    The parameter contains the description of the site script.
    .Parameter Content
    This parameter contains the JSON string for the site script.
    .Parameter Connection
    This parameter provides the context for the call. The default is the current connection
    returned by "Get-PnPConnection".
#>

function Add-SSPSiteScript {
    param(
        $title,
        $description,
        $content,
        $connection = (Get-PnPConnection),
        [Switch] $force
    )

    $scripts = Get-PnPSiteScript -Connection $connection
    $scriptObjs = $scripts | Where-Object {$_.Title -eq $title}
    if ($scriptObjs -and ($scriptObjs.Length -gt 0)) {
        if ($force)
        {
            Write-Host "Modifying Site Script $( $scriptObjs[0].Title ), $( $scriptObjs[0].Id )"
            Set-PnPSiteScript -Identity $scriptObjs[0].Id -Content $content -Connection $connection
        }
        return $scriptObjs[0]
    } else {
        Write-Host "Adding Site Script $title"
        $scriptObj = Add-PnPSiteScript -Title $title -Description $description -Content $content -Connection $connection
        return $scriptObj
    }
}