Build-PorteoSiteListFromTemplate.ps1

<#
    .Synopsis
        Build-PorteoSiteListFromTemplate -TenantUrl "https://mysite-admin.sharepoint.com" -Credentials (Get-Credential) `
                     -SiteList @(@("site1", "Site 1 Title"), @("site2", "Site 2 Title"))
                     -Owner "name@mysite.onmicrosoft.com" -Type "TeamSite" `
                     -SrcConnection $srcConnection

    .Description
        This function builds a *Porteo* site for each item in the site list. A *Porteo* site is a ***SimpleSharepoint*** base site, based on
        either a **TeamSite** or **ComunicationSite** template type and has the following ***SimpleSharepoint*** lists:

        * Site Assets (SiteAssets)
        * Documents (Shared Documents)
        * Journal
        * Requests
        * SiteCollectionList
        * Links
        * SubsiteLists

        At this point, you would create this base site, then add contents to the above lists. You may
        also add some other lists, add to the _SiteAssets_ and any other *Pages* with content and
        branding. This site will be used to provision the specified sites on specified tenant.

        To provision a list of new sites, you first extract a template from the desired site using
        Get-SSPSiteTemplate with a file name (.pnp extension). You then use the `-Template` argument to specify
        this file and use the `-TenantUrl` and `-Credentials` arguments to create the site on the target tenant. See
        the series of Examples below to see the process and sequence of operations.

        Then the target sites are provisioned from the site associated with the template file.

        The site Pages are copied as well as the Pages' contents. Furthermore, the *Porteo* standard lists,
        which are listed above, have their structure and contents copied.

        The examples provide in sequence the process by which you may create a base *Porteo* site, modify it,
        and then use the result to provision another site.

        ***Note***: If a site already exists, this function will notify and skip its creation.
        ***Note***: The site type must match the site type of the source template.

    .Parameter Template
        This paramter holds the template file. It must be a ".pnp" file name.
    .Parameter TenantUrl
        This parameter holds the tenant adminstrative site url, e.g. https://mysite-admin.sharepoint.com
    .Parameter Credentials
        This parameter holds the credentials for the tenant adminstrator that can create sites.
    .Parameter SiteList
        This parameter holds the urls and titles of the sites to be created. It is a list of site specs.
        A site spec is a list of url and site title.
    .Parameter Type
        This paramter holds the type of site to be created, e.g. TeamSite or CommunicationSite.
        This parameter MUST be the same type as the template.
    .Parameter Owner
        This paramter holds the owner of the new site, which is an email address.

    .Example
    $dstCreds = Get-Credential

    Gets the tenant credentials to to build the new site.
    .Example
    $srcCreds = Get-Credential

    Gets the tenant credentials for the source site template.

    .Example
    $srcConn = Connect-PnPOnline -Url https://company.sharepoint.com/sites/site-template -Credentials $srcCreds -ReturnConnection

    Gets the authenticated connection for the template site.
    .Example
    Get-SSPSiteTemplate -FileName /tmp/template.pnp -SrcConnection $srcConn

    Gets and writes the template for the source site to the file /tmp/template.pnp.
    .Example
    $newSiteUrl = Build-PorteoSiteListFromTemplate -Template /tmp/template.pnp
                 -TenantUrl "https://client-admin.sharepoint.com" -Credentials $dstCreds `
                 -SiteList @(@("site1", "Site 1 Title"), @("site2", "Site 2 Title")) -Type "TeamSite" `
                 -Owner "admin@company.com"

    Builds the new sites "Site 1 Title" and "Site 2 Title" at https://client.sharepoint.com/sites/site1 and
    https://client.sharepoint.com/sites/site2 respectively, and provisions them from the
    template file /tmp/template.pnp.
#>


function Build-PorteoSiteListFromTemplate {
    param(
        [parameter(Mandatory=$true)]
        [string]
        $template,
        [parameter(Mandatory=$true)]
        [string]
        $tenantUrl,
        [parameter(Mandatory=$true)]
        [System.Management.Automation.PSCredential]
        $credentials,
        [parameter(Mandatory=$true)]
        [Collections.Generic.List[string[]]]
        $siteList,
        [parameter(Mandatory=$true)]
        [string]
        $owner,
        [parameter(Mandatory=$false,HelpMessage="Default is TeamSite")]
        [string]
        $type = "TeamSite"
    )

    foreach ($item in $siteList) {
        Write-Host "Building site $tenantUrl from Template $template"
        Build-PorteoSiteFromTemplate -Template $template -TenantUrl $tenantUrl -Credentials $credentials `
             -SiteName $item[0] -Title $item[1] -Owner $owner -Type $type
    }

}