Forum Discussion

Naligurtan's avatar
Naligurtan
Brass Contributor
Sep 28, 2023

Migrate SharePoint sites libraries into one SharePoint site

I have over 800 SharePoint sites. Every site has a document library. The name of the document library is “Project Folder”.

I created a SharePoint site. It is called “Projects site”. I also created 800 document libraries in the Project sites.

What I want to do is this:

I want to move/migrate all 800 SharePoint sites’ document libraries into the “Projects site” SharePoint site.

I have an excel file with all SharePoint sites links and document libraries name.

Does anyone know how to do it with PowerShell?

 

8 Replies

  • LeonPavesic's avatar
    LeonPavesic
    Silver Contributor

    Hi Naligurtan,

    To migrate all 800 SharePoint sites' document libraries into the "Projects site" SharePoint site using PowerShell, you can use the following steps:

    1. Install the SharePoint PnP PowerShell module:

     

    Install-Module SharePointPnPPowerShellOnline​

     

     
    1. Connect to your SharePoint tenant:

     

    Connect-PnPOnline -Url https://your-tenant-admin-url.sharepoint.com​

     

     
    1. Create a variable to store the list of SharePoint sites and document libraries:

     

    $sitesAndLibraries = Import-Csv -Path "C:\Path\To\Excel\File.csv"​

     

     
    1. 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)

    • Naligurtan's avatar
      Naligurtan
      Brass 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

      • LeonPavesic's avatar
        LeonPavesic
        Silver 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)

Resources