admin管理员组文章数量:1435859
Hello everyone I have tried copy documents in document library, but have mistake: "Access denied". In code bellow I tried copy one element by id:
$clientId = "**************************"
$clientSecret = "**************************"
$siteUrl = "https://***********.sharepoint/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."
This document library containing documents sets, but in code I tried copy .docx file, but I can`t, what strange in the same site collection I have created two test document library, and this script work fine (I change list path and element id). When I created credentials I have used this instruction. And this creds have FullControl permissions, also I have tried do it using SharePoint account, which have have FullControl permissions in all site collections.
I will be glad for a any answer and help
Hello everyone I have tried copy documents in document library, but have mistake: "Access denied". In code bellow I tried copy one element by id:
$clientId = "**************************"
$clientSecret = "**************************"
$siteUrl = "https://***********.sharepoint/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."
This document library containing documents sets, but in code I tried copy .docx file, but I can`t, what strange in the same site collection I have created two test document library, and this script work fine (I change list path and element id). When I created credentials I have used this instruction. And this creds have FullControl permissions, also I have tried do it using SharePoint account, which have have FullControl permissions in all site collections.
I will be glad for a any answer and help
Share Improve this question edited Nov 16, 2024 at 16:14 Theo 61.5k8 gold badges27 silver badges46 bronze badges asked Nov 15, 2024 at 19:18 Denys KravchenkoDenys Kravchenko 535 bronze badges1 Answer
Reset to default 0The problem was that although the document libraries were in the same site, even visually placed next to each other, one list had a path similar to this: https://blabla.sharepoint/sites/SiteName/Lists/ListName/Forms/AllItems.aspx and the other had a path: https://blabla.sharepoint/sites/SiteName/ListName/Forms/AllItems.aspx And because I was using the same path to access both libraries, this error occurred
本文标签:
版权声明:本文标题:powershell - The Copy-PnPFile method does not copy items from the document library to the SharePoint list - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745675014a2669799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论