Enable Copy-PnPFile / Move-PnpFile to transfer between Odfb and SPO #620
-
I was hoping that I could use Copy-PnPFile to copy a file from OneDrive for Business to SharePoint Online. Unfortunately I can't get it to work. I suspect that being connected to only one root, i.e. https://[tenant].sharepoint.com/ or the mySite https://[tenant]-my.sharepoint.com/ is the issue. One would have to establish a connection to the target. Is this something that could be useful? Or is there already a way? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
having the same case, where I need to do the opposite: from SPO to ODFB... the functionality is available on the web version so I expect it should be available |
Beta Was this translation helpful? Give feedback.
-
I dont think this is currently possible with Copy-PnPFile or Move-PnP file and I suspect this is due to authentication. The way I've had to do it in the past which is a little clunky but works (see example below you could adapt). Is connecting to the OneDrive site, assigning the file to a Stream variable and then connecting to the SP Site and then using it with Add-PnPfile. #Connect To OneDrive
Connect-PnPOnline -Url 'https://tenantname-my.sharepoint.com/personal/username'
#Add the file to Stream Variable
$streamResult = (Get-PnPFile -Url '/personal/username/Documents/Certs/ReportsApp.cer').OpenBinaryStream()
Invoke-PnPQuery # this is will load the clientresult object returned from OpenBinaryStream
#Connect to SP Site
Connect-PnPOnline -Url 'https://tenantname.sharepoint.com/sites/YourSPSite'
Add-PnPFile -FileName 'ReportsApp.cer' -Folder "Shared Documents" -Stream $streamResult.Value |
Beta Was this translation helpful? Give feedback.
I dont think this is currently possible with Copy-PnPFile or Move-PnP file and I suspect this is due to authentication.
The way I've had to do it in the past which is a little clunky but works (see example below you could adapt).
Is connecting to the OneDrive site, assigning the file to a Stream variable and then connecting to the SP Site and then using it with Add-PnPfile.