Add-SSPSiteDesign.ps1

<#
    .Synopsis
    Adds a SOP Site Design using PnP to the site/tennant.
    .Description
    This CmdLet addes a new site design. If no Site Script Ids are defined then it adds
    a bogus one, so that they may be set later.
    .Parameter Title
    This parameter contains the title of the Site Design. Site designs are referenced by their title.
    .Parameter Type
    This parameter contains the type of site to create. It is either 'TeamSite' or 'CommunicationSite'.
    The default is 'TeamSite'.
    .Parameter Description
    This parameter contains the description of the site design.
    .Parameter ScriptIds
    This parameter contains a list of Script titles to add to the site design.
    .Parameter Connection
    This parameter provides the context for the call. The default is the current connection
    returned by "Get-PnPConnection".
#>


function getScriptIds($names) {
    return $names | ForEach-Object { (Get-SSPSiteScript -Title $_).Id }
}

function Add-SSPSiteDesign {
    param(
        $title,
        $type = "TeamSite",
        [string[]] $siteScriptIds,
        $description = "",
        $connection = (Get-PnPConnection),
        [Boolean] $force
    )
    $siteDesigns = Get-PnPSiteDesign -Connection $connection
    $siteDesigns = $siteDesigns | Where-Object {$_.Title -eq $title}
    if ($siteDesigns -and ($siteDesigns.Length -gt 0)) {
        if ($force)
        {
            $scriptIds = getScriptIds($siteScriptIds)
            if ($scriptIds -and ($scriptIds.Length -gt 0))
            {
                Write-Host "Setting Site Design $title"
                Set-PnPSiteDesign -Identity $siteDesigns[0].Id -Description $description -SiteScriptIds $scriptIds -Connection $connection
            }
        }
        return $siteDesigns[0]
    } else {
        $scriptIds = getScriptIds($siteScriptIds)
        if ($scriptIds -and ($scriptIds.Length -gt 0))
        {
            Write-Host "Adding Site Design $title ($scriptIds)"
            $siteDesign = Add-PnPSiteDesign  `
                        -Title $title `
                        -WebTemplate $type `
                        -Description $description `
                        -SiteScriptIds $scriptIds
            return $siteDesign
        }
    }
}