Forum Discussion
Migrate SharePoint sites libraries into one SharePoint site
Hi Naligurtan,
To migrate all 800 SharePoint sites' document libraries into the "Projects site" SharePoint site using PowerShell, you can use the following steps:
- Install the SharePoint PnP PowerShell module:
Install-Module SharePointPnPPowerShellOnline
- Connect to your SharePoint tenant:
Connect-PnPOnline -Url https://your-tenant-admin-url.sharepoint.com
- Create a variable to store the list of SharePoint sites and document libraries:
$sitesAndLibraries = Import-Csv -Path "C:\Path\To\Excel\File.csv"
- Iterate through the list of SharePoint sites and document libraries, and copy the files from each document library to the corresponding document library in the "Projects site" SharePoint site:
foreach ($siteAndLibrary in $sitesAndLibraries) {
$sourceLibraryUrl = $siteAndLibrary["SiteUrl"] + "/" + $siteAndLibrary["LibraryName"]
$targetLibraryUrl = "https://your-tenant-domain.sharepoint.com/sites/Projects/Library/" + $siteAndLibrary["LibraryName"]
Copy-PnPFile -SourceUrl $sourceLibraryUrl -TargetUrl $targetLibraryUrl
}
This script will copy all of the files from each document library in the list of SharePoint sites to the corresponding document library in the "Projects site" SharePoint site. The original files in the source document libraries will not be deleted.
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)
- NaligurtanSep 28, 2023Brass Contributor
Hi LeonPavesic ,
Thanks for your reply.
Can you please let me know the name/title of each column in this file File.csv?
Thanks
- LeonPavesicSep 29, 2023Silver Contributor
Hi Naligurtan,
The Excel file File.csv should have two columns:
- SiteUrl - The URL of the SharePoint site containing the document library.
- LibraryName - The name of the document library.
SiteUrl,LibraryName https://contoso.sharepoint.com/sites/Site1,Project Folder https://contoso.sharepoint.com/sites/Site2,Project Folder // ...
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)
- NaligurtanOct 11, 2023Brass Contributor
Hi LeonPavesic
It does not work because I might have not explained in clearly and you may not have understood me.I will try explain it here again. I am also attaching a screenshot.
There are over 1000 sites on the prem with ONLY one document library (Project%20Folder). I created ONLY one site on SharePoint online. I want to move all sites’ document libraries (Project%20Folder) into the new SharePoint site as a document library with the same name of the prem sites (GP56077, GP56121).
All Site names from the old sites/on prem became a document library name in the new SharePoint site. All files from the Project%20Folder document libraries needs to be moved into the new document libraries such as GP56077, GP56121 etc.Please see the screenshot below.