0

How can I copy a sharepoint list in the same sharepoint environment with powershell. I use the powershell modules "pnppowershell" or "SharepointOnline.CSOM".

Greetings, P

1 Answer 1

1

Using Invoke-PnPSiteTemplate you can copy/import list in SharePoint.

Refer the powershell.

[void] MoveSpoList() {
        # looping through the lists
        $csvInput = Import-Csv -Path '.\Lists.csv'
        foreach ($row in $csvInput) {
            try {

                # Connects SharePoint Online
                Connect-PnPOnline -Url $this.SourceUrl.Trim() -Interactive
                Get-PnPWeb

                $ListName = $row.ListName.Trim();
                $IsLookUpList = $row.IsLookUpList.Trim();
                Write-Host $ListName
                Write-Host $IsLookUpList

                #Getting List Template Name
                $timestamp = Get-Date -Format FileDateTimeUniversal
                $tempFile = './SourceListBackup/' + $ListName + $timestamp + '.xml';

                Get-PnPSiteTemplate -Handlers Lists -ListsToExtract $ListName -Out $tempFile

                #Adding Rows to List Template
                if ($IsLookUpList -eq 1) {
                    Add-PnPDataRowsToSiteTemplate -Path $tempFile -List $ListName -Query '<View></View>'
                }

                #Applying Template to Destination Site
                Connect-PnPOnline -Url $this.DestinationUrl.Trim() -Interactive
                Get-PnPWeb
                Invoke-PnPSiteTemplate -Path $tempFile
            } catch {
                Write-Host -ForegroundColor Red 'Error ', ':', $Error[0].ToString();
                Start-Sleep 10
            }
        }
    }

I have explained in details in below article and code is available to download.

Move SPO List

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.