Copy-PnPFile throws access denied error when copying to a subfolder in target library
Reporting an Issue or Missing Feature
I'm using Copy-PnPFile command to copy a file from one document library to another document library. The copying throws error when copying to a subfolder in the target document library though the target folder does exist
This script doesn't work though Folder1 exists in Lib2 Copy-PnPFile -SourceUrl "Lib1/Folder1/Myfile.xlsx" -TargetUrl "Lib2/Folder1/Myfile.xlsx"
However copying directly to target library works Copy-PnPFile -SourceUrl "Lib1/Folder1/Myfile.xlsx" -TargetUrl "Lib2/Myfile.xlsx"
Expected behavior
Expect the file to be copied to specified subfolder
Actual behavior
Get access denied error
Steps to reproduce behavior
Copy-PnPFile -SourceUrl "Lib1/Folder1/Myfile.xlsx" -TargetUrl "Lib2/Folder1/Myfile.xlsx"
Which version of the PnP-PowerShell Cmdlets are you using?
- [ ] PnP PowerShell for SharePoint Online
What is the version of the Cmdlet module you are running?
3.13.1909.0
How did you install the PnP-PowerShell Cmdlets?
- [ ] Installed through the PowerShell Gallery with Install-Module
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
This issue is already addressed in #2195 and #2240
This issue is already addressed in #2195 and #2240 @andikrueger Thanks for coming back. However my issue is not the same as copying to empty folder. I'm copying a file from a folder in a document library to a folder in another library in the same site collection. And I get access denied error. I've version 3.13.1909.0 installed
Thank you for the clarification. The PR mentioned addressed another issue, but it fixed several things with folders and the process on how to create a non existing path. I will do a quick test with the latest changes.
Does your target folder exist and does it inherit permissions? If not I would address this issue too.
Thanks @andikrueger . The folder does exist on the target library and it does inherit permissions. As I loop through the source folders recursively, I create folder items in the target library. When the item is file, I call Copy-PnPFile passing the source and target locations.
I noticed the Move-PnPFile command works fine, however it doesn't fit my use case as I need to copy metadata. I'm copying the file first and then update the metadata from source to target.
@andikrueger I just downloaded the latest version 3.14.1910.0 and get the same error.
Copy-PnPFile -SourceUrl "Lib1/Folder1/Myfile.xlsx" -TargetUrl "Lib2/Folder1/Myfile.xlsx"
I've tried prefixing the site relative path, but no success. If I remove Folder name in target url, it works
- My first test was successful and I was able to copy the file into a folder.
- My second test failed with an "Access denied" error.
Thanks @andikrueger. What was the difference between these 2 tests? Could you please send the script you used for the first test and I'll try at my end
That’s the hard part to figure out at the moment. I really can’t tell. I did use the same commands - but maybe the PnP PowerShell Version was different, as I did have a custom version in my modules directory.
@andikrueger Is there any specific PnP version that I can use till you release the fix?
I was able to find the difference between my test 1. and 2.
- Works fine with a version based on PR #2240.
- Was run with the latest and previous versions of the PnP PowerShell.
I was able to find the difference between my test 1. and 2.
- Works fine with a version based on PR #2240.
- Was run with the latest and previous versions of the PnP PowerShell.
Thanks @andikrueger. When will the #2300 fixes be released for download?
@rjn71 Hopefully with the next release. The PR got merged.
Yup, november release is the next scheduled release unless you want to build it yourself off the dev branch.
Thanks @wobba. Is it the beginning of November? I've got some tasks scheduled which is dependent on this. I'll move the dates accordingly
@rjn71 we typically release the first week of the month. You can always pull down the dev branch of core and powershell and build it yourself if you cannot wait.
The fix is part of the intermediate release: https://github.com/SharePoint/PnP-PowerShell/releases/tag/3.14.1910.1