使用Copy-PnPFile复制SharePoint文档遇权限拒绝问题求助
I'm getting an Access denied error when trying to copy document sets (including their .docx files) between two SharePoint Online document libraries.
Oddly, the script works without issues when using two newly created test libraries in the same site collection, but fails consistently on our production libraries.
I've already tried:
- Using an app registration with FullControl permissions on the site collection
- Running the script with a SharePoint account that has FullControl access across all site collections
Here's the code I'm using to copy a single document set by ID:
$clientId = "**************************" $clientSecret = "**************************" $siteUrl = "https://***********.sharepoint.com/sites/TransportClaimsDatabase/" $SourceLibrary = "Claims (test)" $DestinationLibrary = "Claims (Archive)" # Define the source and destination URLs for the document set $SourceUrl = "/sites/TransportClaimsDatabase/$SourceLibrary/$DocumentSetName" $TargetUrl = "/sites/TransportClaimsDatabase/$DestinationLibrary/$DocumentSetName" Write-Host "Connecting to $siteUrl" -ForegroundColor Yellow # Connect-PnPOnline -Url $siteUrl -UseWebLogin Connect-PnPOnline -Url $siteURL -ClientId $clientId -ClientSecret $clientSecret ##################################################################################################### $DocumentSetIDToCopy = "16" $DocumentSet = Get-PnPListItem -List $SourceLibrary -Id $DocumentSetIDToCopy $DocumentSetName = $DocumentSet["FileLeafRef"] $SourceUrl = "/sites/TransportClaimsDatabase/$SourceLibrary/$DocumentSetName" $TargetUrl = "/sites/TransportClaimsDatabase/$DestinationLibrary/$DocumentSetName" Write-Output "`nProcessing Document Set: $DocumentSetName with ID: $DocumentSetIDToCopy" Write-Output "SourceUrl: $SourceUrl" Write-Output "TargetUrl: $TargetUrl" try { Copy-PnPFile -SourceUrl $SourceUrl -TargetUrl $TargetUrl -OverwriteIfAlreadyExists -Force Write-Output "Successfully copied $DocumentSetName to $DestinationLibrary." } catch { Write-Output "Failed to copy $DocumentSetName. Error details:" $_ | Format-List -Force } ##################################################################################################### # Disconnect Disconnect-PnPOnline Write-Output "Document Sets have been successfully moved from $SourceLibrary to $DestinationLibrary."
I need help figuring out why this access denied error only happens on the production libraries and how to fix it.
内容的提问来源于stack exchange,提问作者Denys Kravchenko
相关产品推荐
相关产品推荐

