Copy Documents From One SharePoint Document Library To Another Based On Created Date

In this article you will learn how to copy documents from one SharePoint Document Library to another based on created Date using PowerShell.


Welcome to an article on how to copy documents from one SharePoint Document library to another based on Created Date using PowerShell.

I searched the web everywhere and didn’t find this script so I thought of writing it down for my readers. Sometimes we need some of our files in another document library based on some interval of period from the date it was created.

You have a choice, using this script which will move the files based on your input as in from how many days from today you want the files which were created or uploaded during this time zone.

How? Let’s see it.


1. Open Windows PowerShell Modules as an Administrator.


Code:


Call the Web

  1. $web = Get-SPWeb "Add your web collection here"

Get the library

  1. $list = $web.Lists["Add your library name here"]  

  2. $spQuery = New-Object Microsoft.SharePoint.SPQuery  

  3. $spQuery.ViewAttributes = "Scope='Recursive'";  

  4. $spQuery.RowLimit = 2000  

Get the Current Date here

  1. $a = Get-Date   

Add the date from when you want the photos to be pulled as in from today until how many last days

  1. $twoday = $a.AddDays(-4)  $v = Get-Date $twoday -Format s  

Query the list

  1. Write - Host $v