Hi guys, let’s explore a powerful automation for the archival of large libraries using PnP with CSOM PowerShell. This approach can be used for an automatic/semi-automatic/manual way, as per the business needs on a weekly/monthly/quarterly basis, as per the archival needs.
Install all the necessary DLL files by just going to this link >> Click Download >> Select the Latest File. Once the installation is done, you can see a few DLL files automatically reflected on your Local Path, like:
“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”
“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”
Also, install the SharePointPnPPowerShellOnline.msi by going to this link.
Maintain the same Columns, Data Types, Views both in Source Library and Target Library, mostly alldocuments.aspx
PowerShell Scripts Used
The library scan is performed with all Nested Folders and Files, whichever has the Archive Flag manually set to ‘True’ OR scanned if they are 1 year old/n number of days old as per your Archival Strategy[LibScan.ps1].


We shall get all the List of Files to be Archived as per the above-highlighed conditions using a Where Clause at your Local Path:  D:\LibraryDocumentsInventory.csv
It should contain the following columns:
  • FileName
  • RelativeURL
  • CreatedBy
  • CreatedOn
  • ModifiedBy
  • ModifiedOn
  • FileSize
Copying all the Scanned Files with their Relative Folder Paths from the Source Library to the Archive Target Library[CopyFiles.ps1]:
Just give your inputs as per the above-highlighted areas.
Use Only Site Collection Admin/Global Admin Login details for Logging in while the script running is on progress. 
Try to hard code with password-protected security string oriented Token Management on the above scripts for no End User manual inputting involvement. 
You will find all the listed files from that CSV report which have been selected for Archival created with Meta Data properties preserved on the Target Archive Library.
Creative Idea
You can merge both the above scripts for Automation using Flow/Azure Functions and make them run on a Weekly/Monthly scheduled basis that promotes automation without Manual Intervention.
You can apply the above-discussed process with Large Lists too that needs to be Archived.
Since we have a buffer size limit of 100 MB for a Complete Flow-based Copying of Files we are using PnP + CSOM PowerShell to run evergreen unlimited calls no pricing/no size limitation/metadata preserving, etc. hostforlifebanner