PnP-PowerShell icon indicating copy to clipboard operation
PnP-PowerShell copied to clipboard

Copy-PnPFile throws access denied error when copying to a subfolder in target library

Open rjn71 opened this issue 7 years ago • 17 comments

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

rjn71 avatar Oct 07 '19 16:10 rjn71

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

ghost avatar Oct 07 '19 16:10 ghost

This issue is already addressed in #2195 and #2240

andikrueger avatar Oct 07 '19 18:10 andikrueger

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

rjn71 avatar Oct 07 '19 19:10 rjn71

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.

andikrueger avatar Oct 07 '19 21:10 andikrueger

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.

rjn71 avatar Oct 07 '19 21:10 rjn71

@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

rjn71 avatar Oct 08 '19 13:10 rjn71

  1. My first test was successful and I was able to copy the file into a folder.
  2. My second test failed with an "Access denied" error.

andikrueger avatar Oct 08 '19 14:10 andikrueger

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

rjn71 avatar Oct 08 '19 14:10 rjn71

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 avatar Oct 08 '19 14:10 andikrueger

@andikrueger Is there any specific PnP version that I can use till you release the fix?

rjn71 avatar Oct 08 '19 22:10 rjn71

I was able to find the difference between my test 1. and 2.

  1. Works fine with a version based on PR #2240.
  2. Was run with the latest and previous versions of the PnP PowerShell.

andikrueger avatar Oct 09 '19 06:10 andikrueger

I was able to find the difference between my test 1. and 2.

  1. Works fine with a version based on PR #2240.
  2. Was run with the latest and previous versions of the PnP PowerShell.

Thanks @andikrueger. When will the #2300 fixes be released for download?

rjn71 avatar Oct 09 '19 11:10 rjn71

@rjn71 Hopefully with the next release. The PR got merged.

andikrueger avatar Oct 11 '19 12:10 andikrueger

Yup, november release is the next scheduled release unless you want to build it yourself off the dev branch.

wobba avatar Oct 11 '19 13:10 wobba

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 avatar Oct 14 '19 08:10 rjn71

@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.

wobba avatar Oct 14 '19 10:10 wobba

The fix is part of the intermediate release: https://github.com/SharePoint/PnP-PowerShell/releases/tag/3.14.1910.1

andikrueger avatar Oct 31 '19 10:10 andikrueger