Copy-PorteoLists.ps1

<#

    .Synopsis
    Copy-PorteoList -ListName "NameOfList" -SrcConnection $srcConn -DestConnection $dstConn
    .Description
    This function copies the Sharepoint list specified by the `-ListName` argument. It copies the list
    from the site specified by `-SrcConnection` argument and copies the list to the
    destination site specified by the `-DestConnection argument.
    .Example
    $srcSite = "https://client1.sharepoint.com/sites/BaseSite"
    $dstSite = "https://client2.sharepoint.com/sites/NewSite"
    $srcCreds = Get-Credential
    $dstCreds = Get-Credential
    $srcConn = Connect-PnPOnline -Url $srcSite -Credentials $srcCreds
    $dstConn = Connect-PnPOnline -Url $dstSite -Credentials $dstCreds
    Copy-PorteoList -ListName "NameOfList" -SrcConnection $srcConn -DestConnection $dstConn

#>


function Copy-PorteoList {
    param(
        $listName,
        $srcConnection = (Get-PnPConnection),
        $destConnection = (Get-PnPConnection)
    )
    $data = Get-SSPListData -ListName $listName -Connection $destConnection
    if (-not $data -or $data.length -eq 0) {
        Copy-SSPList -ListName $listName -SrcConnection $srcConnection -DestConnection $destConnection
    } else {
        Write-Host "No Data for $listName, no copy"
    }
}

<#

    .Synopsis
    Copy-PorteoLists -ListNames ("List1", "List2", "List3") -SrcConnection $srcConn -DestConnection $dstConn
    .Description
    This function copies the lists specified by the -ListNames argument and copies them from the site
    specified by the `-SrcConnection` argument and copies the list to the
    destination site specified by the `-DestConnection argument.

    If the list names are not specified, the default lists for a *Porteo* site are copied, which are
    *Journal*, *Links*, *Requests*.
    .Example
    $srcSite = "https://client1.sharepoint.com/sites/BaseSite"
    $dstSite = "https://client2.sharepoint.com/sites/NewSite"
    $srcCreds = Get-Credential
    $dstCreds = Get-Credential
    $srcConn = Connect-PnPOnline -Url $srcSite -Credentials $srcCreds
    $dstConn = Connect-PnPOnline -Url $dstSite -Credentials $dstCreds
    Copy-PorteoList -ListName ("List1", "List2", "List3") -SrcConnection $srcConn -DestConnection $dstConn

#>


function Copy-PorteoLists {
    param(
        $listNames,
        $srcConnection = (Get-PnPConnection),
        $destConnection = (Get-PnPConnection)
    )

    if (-not $listNames) {
        $listNames = ("Journal", "Links", "Requests")
    }
    foreach ($listName in $listNames) {
        Copy-PorteoList -ListName $listName -SrcConnection $srcConnection -DestConnection $destConnection
    }
}