question

HamidSadeghpourSaleh avatar image
0 Votes"
HamidSadeghpourSaleh asked Cloudarijit-8685 answered

Copy Content Of a Folder to Another SP Online Folder

Hello Experts,

I'm facing an issue while I want to copy just contents of a folder in "Documents" of a site to another SP Online environment site to a folder, and i want to achieve this with a Powershell script. I've created a list and an item which represents destination and source folder and links and I'm using Sharegate Powershell module commands to write the scripts however it's also possible to use without sharegate.

Any solutions?

Thanks in advance.

office-sharepoint-online
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

After 2 weeks, have you get any update about your question? I am looking forward to hear you back.

0 Votes 0 ·
JerryXu-9587 avatar image
0 Votes"
JerryXu-9587 answered HamidSadeghpourSaleh commented

You can use Copy-PnpFile to do so. It copies a file or folder to a different location. This location can be within the same document library, same site, same site collection or even to another site collection on the same tenant. Currently there is a 200MB file size limit for the file or folder to be copied.

If you have not tried Pnp before, remember to install the module first.

Here is a demo works in my end.

 #Copy File to Another Site
 $sourceSiteURL="SourceSiteURL"
 $UserName="Account"
 $Password = "PWD"
 $SourceURL="Shared Documents/folder"
 $TargetURL="/sites/<siteName>/Shared Documents"
     
 $SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
 $Cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
     
 #Connect to PNP Online
 Connect-PnPOnline -Url $sourceSiteURL -Credentials $Cred
 Copy-PnPFile -SourceUrl $SourceURL -TargetUrl $TargetURL -OverwriteIfAlreadyExists


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello,

Copy-PnPFile doesn't copy folder to another site! I've tried it however didn't help.

Thank you

0 Votes 0 ·

Would you like to say a bit more about your failure on using Copy-PnPFile? Are you copying files to a site in another tenant? Just like I mentioned, it shall works for libraries, sites, and site collections in the same tenant. If possible would you like to share us with your script so we can have a check on it.

0 Votes 0 ·
PriyankaSingh-9873 avatar image
0 Votes"
PriyankaSingh-9873 answered

you can try and use Sharegate for the same if its helpful.
Thanks

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Cloudarijit-8685 avatar image
0 Votes"
Cloudarijit-8685 answered

Hi @HamidSadeghpourSaleh,

Interesting to see copypnpfile has a restriction on same tenant in the documentation,
"This location can be within the same document library, same site, same site collection or even to another site collection on the same tenant"

Since you want to copy between two different tenant, so choices are any of the migration tool OR

by downloading content to local temp folder and then uploading to the destination.
For downloading files, you can use getpnpfile

 Get-PnPFile -Url $File.ServerRelativeUrl -Path $LocalDriveFolderPath -FileName $File.Name -AsFile  

While for uploading, you can use addpnpfile

 Add-PnPFile -Path sample.docx -Folder "Documents" -NewFileName "differentname.docx"








5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.