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.
Call the Web
$web = Get-SPWeb "Add your web collection here"
Get the library
$list = $web.Lists["Add your library name here"]
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes = "Scope='Recursive'";
$spQuery.RowLimit = 2000
Get the Current Date here
$a = Get-Date
Add the date from when you want the photos to be pulled as in from today until how many last days
$twoday = $a.AddDays(-4) $v = Get-Date $twoday -Format s
Query the list
Write - Host $v