Build-PorteoSite.ps1

<#
    .Synopsis
        Build-PorteoSite -TenantUrl https://site-admin.sharepoint.com -Credentials (Get-Credential) `
                     -SiteName "Site1" -Title "The Site" -Owner "name@site.onmicrosoft.com" -Type "TeamSite" `
                     -SrcConnection $srcConnection

    .Description
        This cmdlet builds a "Porteo" site. If the -SrcConnection argument is specified, the
        site gets built, and then it is provisioned from the site associated with the src connection.
        The site Pages are copied as well as the Page Contents. Furthermore the Porteo Standard lists
        have their values copied (See below). Then the contents of the following folders are copied
        from the src connection:
            * Site Assets
            * Documents (Shared Documents)
        If the connection is not specified, then the specified type of site is built adding the following
        predefined lists, using the SiteDesigns methodology:
            * SiteAssets
            * Journal
            * Requests
            * SiteCollectionList
            * Links
            * SubsiteLists
    .Parameter TenantUrl
        This parameter holds the tenant adminstrative site url. Ex. site-admin.sharepoint.com
    .Parameter Credentials
        This parameter holds the credentials for the tenant adminstrator.
    .Parameter SiteName
        This parameter holds the name of the site to be created
    .Parameter Title
        This parameter holds the title for the site to be created.
    .Parameter Type
        This paramter holds the type of site to be created, TeamSite or CommunicationSite.
    .Parameter Owner
        This paramter holds the owner of the new site,email address;
    .Parameter SrcConnection
        This paramter holds the source to copy the template from. If not specified, no template is copied.
    .Example
    $creds = Get-Credential

    Gets the Credential for the subsequent examples
    .Example
    $siteUrl = Build-PorteoSite -TenantUrl https://site-admin.sharepoint.com -Credentials $creds `
                 -SiteName "SiteTemplate" -Title "The Site Template" -Type "TeamSite" `
                 -Owner "name@site.onmicrosoft.com"

    Builds the first site to use as a template. Now, modify this site adding to lists, pages, documents.
    .Example
    $srcConn = Connect-PnPOnline -Url $siteUrl -Credentials $creds

    Gets the connection for the template site from which you will copy.
    .Example
    $dstCreds = Get-Credential

    Gets the tenant credentials to to build the new site.
    .Example
    $newSiteUrl = Build-PorteoSite -TennatUrl https://client-admin.sharepoint.com -Credentials $dstCreds `
                 -SiteName "MySite" -Title "My Great Site" -Type "TeamSite" `
                 -Owner "admin@company.com" -SrcConnection $srcConn

    Builds the new site "MySite" from the template site on a different tenant.
#>


function Build-PorteoSite {
    param(
        [parameter(Mandatory=$true)]
        [string]
        $tenantUrl,
        [parameter(Mandatory=$true)]
        [Object]
        $credentials,
        [parameter(Mandatory=$true,HelpMessage="No spaces")]
        [string]
        $siteName,
        [parameter(Mandatory=$true)]
        [string]
        $title,
        [parameter(Mandatory=$true)]
        [string]
        $owner,
        [parameter(Mandatory=$false,HelpMessage="Default is TeamSite")]
        [string]
        $type = "TeamSite",
        [parameter(Mandatory=$false)]
        [Object]
        $srcConnection
    )

    $connection = Connect-PnPOnline -Url $tenantUrl -Credentials $credentials -ReturnConnection
    $baseUrl = $tenantUrl.Replace("-admin", "")
    $siteurl = "$baseUrl/sites/$siteName"
    $site = Get-PnPTenantSite -Url $siteUrl  -ErrorAction SilentlyContinue
    if (-not $site)
    {
        $site = Add-SSPSite -Owner $owner -Url $siteUrl -Title $title -SiteName $siteName -Type $type -Connection $connection
        $siteUrl = $site

        Write-Host $siteUrl

        $destConn = Connect-PnPOnline -Url $siteUrl -Credentials $credentials -ReturnConnection
        $ignore = Set-PnpSite -NoScriptSite $false -Connection $destConn

        $ignore = Add-PorteoSiteDesigns -Type $type -Connection $connection

        if ($srcConnection)
        {
            $ignore = Copy-SSPSite -SrcConnection $srcConnection -DestConnection $destConn -Handlers $handlers
        } else {
            $ignore = New-PnPList -Title "Site Assets" -Template DocumentLibrary -OnQuickLaunch -Connection $destConn
            $ignore = Invoke-SSPSiteDesigns -SiteDesigns ("DefaultDesign", "AddJournal", "AddLinks", "AddRequests", "AddSiteLists") -Connection $destConn
        }
        return $siteUrl
    } else {
        Write-Host "Site $siteUrl Exists"
        return $siteUrl
    }
}


$handlers = @(
    "AuditSettings",
    "ComposedLook",
    "CustomActions",
    "ExtensibilityProviders",
    # "Features",
    "Fields",
    "Files",
    "Lists",
    "Pages",
    "Publishing",
    "RegionalSettings",
    "SearchSettings",
    "SitePolicy",
    "SupportedUILanguages",
    "TermGroups",
    "Workflows",
    "SiteSecurity",
    # "ContentTypes",
    "PropertyBagEntries",
    "PageContents",
    "WebSettings",
    "Navigation", # This seems to duplicate the naviagion sidebar.
    "ImageRenditions",
    # "ApplicationLifecycleManagement",
    # "Tenant",
    "WebApiPermissions",
    "SiteHeader",
    "SiteFooter",
    "Theme",
    "SiteSettings",
    "SyntexModels"
)