powershell
powershell copied to clipboard
[FEATURE] - Copy-PnPFile from SPO to ODB
Reporting an Issue or Missing Feature
Copy-PnPFile does not work if -SourceUrl is /sites/something/Shared Documents/ and -TargetUrl is /personal/someone_domain_com/Documents it works properly if both are /sites/... or both are /personal/...
Expected behavior
should be able to use it to copy items from sharepoint online to onedrive for business.
Actual behavior
The remote server returned an error: (404) Not Found.
Steps to reproduce behavior
Please include complete script or code samples in-line or linked from gists
What is the version of the Cmdlet module you are running?
(you can retrieve this by executing Get-Module -Name "PnP.PowerShell" -ListAvailable
)
Which operating system/environment are you running PnP PowerShell on?
- [ ] Windows
- [ ] Linux
- [ ] MacOS
- [ ] Azure Cloud Shell
- [ ] Azure Functions
- [ ] Other : please specify
@omarmallat - This is not a bug as such. There are some authentication challenges when copying from SPO to ODFB unfortunately. You can have a look at the discussion here if you want to try (although it's talking the opposite way ODFB to SPO) but you may try to adjust.
I'll classify as enhancement.
hi @omarmallat , we have fixed this issue with the latest nightly builds.
You will need to provide a full destination URL for this to work.
i.e , the -TargetUrl
parameter value needs to be something like https://tenant-my.sharepoint.com/personal/..
The source URL value should be as it is.
@gautamdsheth just wanted to add that your updates in the nightly build worked well for me as well. This is a hugely appreciated update as it helped me meet a need to copy missing files from OneDrive to SharePoint Online. Thank you!
Hello, may I ask how you're connecting to 2 different sites and using this method? I have been unsuccessful in connecting to multiple sites, such as a ODFB and a SharePoint site in order to transfer files.
I can confirm it's working now. My concept was to copy from SharePoint to OneDrive in 3 steps:
- Connect to destination OneDrive and make sure the container folder is created.
- Connect to the source SharePoint
- Copy a specific file/folder to the destination
I used the following code:
$DestinationConn = Connect-PnPOnline -URL $DestinationSiteURL -Interactive -ReturnConnection
$DestinationRelativePath = $OneDriveDefaultListName + "/" + $DestinationFolderPath
try {
Add-PnPFolder -Connection $DestinationConn -Name $DestinationProjectName -Folder $DestinationRelativePath
}
catch {
Write-Host "The project's folder $($SourceSiteCode) already exists in the destination. No need to create it."
}
$SourceConn = Connect-PnPOnline -URL $SourceSiteURL -Interactive -ReturnConnection
try {
Copy-PnPFile -Connection $SourceConn -SourceUrl $f.ServerRelativeUrl -TargetUrl $DestinationLibraryURL -Force -OverwriteIfAlreadyExists
}
catch {
write-host -f Red "Error:" $_.Exception.Message
}
the code above was used with the following criteria:
- I had to include the parameter -Connection
- SourceUrl is only the relative URL, where it starts with /sites/SITENAME/Share Documents/PATH_TO_FOLDER_OR_FILE
- TargetUrl is the full path starting from https://TENANT-my.sharepoint.....