Back to Blog
SharePoint Online PowerShell

Copy Files in another Library in SharePoint Using PowerShell

Copy Files in another Library in SharePoint Using PowerShell

In today’s post, we will look at how to copy files from one library to another using PnP 


This is a process that can be easily performed through the SharePoint Online end-user interface as well.

First, locate the site containing the library from which you want to copy the files.
 
image
Next, locate the destination site and the corresponding library where the files will be copied.
 
image
Return to the source list and select the items.
 
image
Then, click on the three dots (ellipsis) and select "Copy to."
 
image
In the pop-up window, find the destination site and library, and then select "Copy here."
 
image

image
Alternatively, you can use the following PowerShell script to handle the transfer in an automated way:

$siteUrl = "https://yourtenant.sharepoint.com/sites/your-site"
$sourceLibUrl = "/sites/your-site/SourceLibrary" # source library url
$targetLibUrl = "/sites/your-site/TargetLibrary" # target library url

# Connection to SharePoint Online
Connect-PnPOnline -Url $siteUrl -Interactive

# Copy all folders and items
Write-Host "Έναρξη αντιγραφής από $sourceLibUrl σε $targetLibUrl..." -ForegroundColor Green

Copy-PnPFile -SourceUrl $sourceLibUrl -TargetUrl $targetLibUrl -OverwriteCopy -Force

Write-Host "Η αντιγραφή ολοκληρώθηκε επιτυχώς!" -ForegroundColor Red