Forum Discussion
Migrate SharePoint sites libraries into one SharePoint site
Hi Naligurtan,
thanks for the update, I understand your issue better now.
Here is a PowerShell script that you can use to migrate all of the document libraries from your SharePoint on-premises farm to a single document library in SharePoint Online, with the same name as the original document libraries (you can use it perhaps as a starting point)
# Import the SharePoint PnP PowerShell module
Install-Module SharePointPnPPowerShellOnline
# Connect to your SharePoint on-premises farm
Connect-PnPOnline -Url https://your-onprem-sharepoint-farm-url
# Create a variable to store the list of SharePoint on-premises sites
$onpremSites = Get-PnPSite
# Create a variable to store the target document library URL in SharePoint Online
$targetLibraryUrl = "https://your-tenant-domain.sharepoint.com/sites/Projects/Library/"
# Iterate through the list of SharePoint on-premises sites
foreach ($onpremSite in $onpremSites) {
# Get the document library name in the SharePoint on-premises site
$sourceLibraryName = "Project%20Folder"
# Create the target document library in SharePoint Online if it does not exist
if (-Not (Test-PnPList -ListUrl $targetLibraryUrl/$sourceLibraryName)) {
New-PnPList -ListName $sourceLibraryName -TemplateId "100" -ParentSiteUrl $targetLibraryUrl
}
# Get the document library URL in the SharePoint on-premises site
$sourceLibraryUrl = $onpremSite.Url + "/" + $sourceLibraryName
# Copy the files from the SharePoint on-premises document library to the target document library in SharePoint Online
Copy-PnPFile -SourceUrl $sourceLibraryUrl -TargetUrl $targetLibraryUrl/$sourceLibraryName
}
This script should first check if the target document library exists in SharePoint Online. If it does not exist, the script should create it.
Then, the script should copy all of the files from the SharePoint on-premises document library to the target document library in SharePoint Online.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)
Naligurtan I recommend you look at ShareGate for large-scale migrations like this. It's expensive but saves a lot of hassle.
Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP UK (and classic 1967 Morris Traveller driver)
- NaligurtanOct 12, 2023Brass Contributor
Hi Rob_Elliott,
I could find a way to automate it with ShareGate. It is NOT site to site migration. It is sites' document libraries to a site migration.
How ever, if you have any solution please share with us.
Thanks