(SharePoint Server 2019)
I would like to export all document libraries/lists from my old "NG-Portal" site on our old web application and import it into the new "NGPortal" site on our current web application using SharePoint Management PowerShell. However, I am unsure on the best layout for the commands. Could someone assist with the best command sequence to achieve this request. My initial thoughts were to use something like this below to start however I need clarification on what should be inserted for Web URL, back up path and Item URL?
Export-SPWeb <Web-URL> -Path <Backup-Path> -ItemURL <Library-URL> -IncludeUserSecurity -IncludeVersions All
The Export-Import all lists and libraries from one site to another site using PowerShell guidance isn't that clear as to which sections need to be filled in with my own data and what is part of the template.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
#Custom PowerShell Function to Export All Lists and Libraries from a SharePoint site
Function Export-AllLists($WebURL, $ExportPath)
{
#Get the source web
$web = Get-SPWeb $WebURL
#Check the Local Folder export Lists
#Get all lists - Exclude System lists
$ListCollection = $web.lists | Where-Object { ($_.hidden -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false) -and ($_.Author.LoginName -ne "SHAREPOINT\system") }
#Iterate through each list and export
foreach($list in $ListCollection)
{
Write-host "Exporting: " $list.Title
#Remove : from List title - As we can't name a file with : symbol
$ListTitle = $list.Title.Replace(":",[string]::Empty)
Export-SPWeb $WebURL -ItemUrl "/$($list.RootFolder.Url)" -IncludeUserSecurity -IncludeVersions All -path ($ExportPath + $ListTitle+ ".cmp") -nologfile
}
}
#Custom PowerShell Function to Export All Lists and Libraries from a SharePoint site
Function Import-AllLists($WebURL, $ImportPath)
{
#Get the Target web
$web = Get-SPWeb $WebURL
#Check the Local Folder export Lists
#Get all File Backups to Import
$FilesCollection = Get-ChildItem $ImportPath
#Iterate through each file and import
foreach($File in $FilesCollection)
{
Write-host "Importing: " $File.Name
Import-SPWeb $webURL -path $ImportPath$File -includeusersecurity -UpdateVersions Overwrite -nologfile
}
}
#Call the function to export
Export-AllLists "https://sales.crescent.com/" "D:\Backup\"
#To import, Use:
#Import-AllLists "https://marketing.crescent.com/" "D:\Backup\"
Also, if I did just do a standard library import/export via central admin can permissions be kept?