Copy all SharePoint Files and Folders Using PowerShell

This script uses PowerShell to copy all files and folders from one document library to another document library.  This script will allow you to copy an entire document library, along with user-defined metadata from one site collection to another.

4.4 Star
14,743 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Help needed to export contents from an asset library to file share preserving metadata
    1 Posts | Last post June 28, 2016
    • Roger, 
      Could you please share Power Shell script to export contents from an asset library to windows file share preserving metadata in it?
  • Copying Documnet sets and their files instead of folders
    1 Posts | Last post April 01, 2016
    • Hi Roger,
      I am looking at this script to see if this would help me with my migration. I have two sites. Each have a document library with Document Sets in them and in those document sets their are multilple files.
      I need to migrate those into the a single site, that has 4 document libraries and each of those can support the Document Set content types and the other content types that exist for the files.
      I only care about the metadata and properties that exist so I don't want to add any fields that don't already exist. (Assuming that I would comment out the addproperty for both sections)
      However, to change this script for Document Sets would I just add a section (like the new folder section ) to add the folder with the [Microsoft.Shaerpoint.DocumentSet]:: DocumentSet parameter?
      Or am I missing something here?
      Oh and I need to make sure I direct the right Documentsets to the right target libraries. ...
      Let me know if you need more info..
  • Files are getting copied but not the Folder
    1 Posts | Last post March 31, 2016
    • Hi Roger,
      I tried your script with the modifications as mentioned in the comment section. Still its not working for me, the files at the library level are getting copied but not the folders. The error which I am getting is 
      ins characters that are not permitted.  Please use a diffe
      At C:\Users\rahul.kumar2\Desktop\FileCopies8.ps1:75 char:2
      +         $NewFolder.update <<<< ()
          + CategoryInfo          : NotSpecified: (:) [], Method
          + FullyQualifiedErrorId : DotNetMethodException
      You cannot call a method on a null-valued expression.
      At C:\Users\rahul.kumar2\Desktop\FileCopies8.ps1:93 char:4
      +             $dFile = $Newfolder.Folder.Files.Add <<<< ($
      tes, $true)
          + CategoryInfo          : InvalidOperation: (Add:Strin
      Thanks in Advance. Any help on this would be really appreciable.
  • Copying files but not folders
    1 Posts | Last post November 25, 2015
    • Hi Roger,
      I made the changes with regard to $Relative to correct those errors. It is copying files but not a test folder in the library named New Folder. I am getting the following:
      "Exception calling "Update" with "0" argument(s): "The file or folder contains characters that are not permitted. Please use a different name."
      at copyfiles.ps1:122 char:26
      Line 122 consists of:         $NewFolder.update()
      Thanks for any help you can provide.
  • I cannot get this to run on my 2010 farm, please help
    1 Posts | Last post October 28, 2015
    • It seems I cannot post my code, but here is a link to it. It seems to not like the URL despite the URL existing..
  • SharePoint 2013 / Office 365
    2 Posts | Last post April 21, 2015
    • As you tagged SharePoint 2010, can we implement on SharePoint 2013
    • I haven't tested for SharePoint 2013, but there's nothing specific to SharePoint 2010 that wouldn't work in SharePoint 2013.
  • Does this script preserve the permissions?
    2 Posts | Last post April 21, 2015
    • Does this script preserve the permissions?
    • This script does not preserve permissions of the document library.  Once the files are copied over, they will all inherit from the parent.
  • same site collection
    1 Posts | Last post February 11, 2015
    • that great post, my question is that is it possible to use your code for copy one document librray to another in same site collection as well?? or I need tio change it
  • Does this script supports versioning
    2 Posts | Last post January 07, 2015
    • Does this script supports versioning?
    • This version of the script does not maintain version history of files.  You may want to look into the SharePoint Migration Framework:
  • Is there a SharePoint 2013 Online version?
    2 Posts | Last post January 07, 2015
    • Is there, or perhaps the possibility, of something like this being written for SharePoint 2013 Online? From what I can tell, the PowerShell library for Online does not contain the necessary routines to perform the necessary Tasks.
    • I would have to look into this.  I know that Kimmo Forss has put together a pretty comprehensive migration framework.  Might be able to find it there:
11 - 20 of 27 Items