首页 > 解决方案 > Sharepoint/Powershell 中的代码问题

问题描述

所以这是我的问题,我们想在我的公司自动化记事本(Sharepoint)的副本,我们已经有允许我们从共享点站点复制链接的 power-automate 脚本,这是允许您恢复的 Power shell 代码站点文件并将它们复制到另一个:

$SiteURL = "https://******.sharepoint.com/sites/********"
$TargetFolderURL = "/sites/*********/*****"
$SitestoCopy = "copy"

Connect-PnPOnline -Url $SiteURL -UseWebLogin

$items = Get-PnPListItem -List $SitestoCopy

Write-Host "Nombre total d'éléments :" $items.Count

ForEach ($item in $items) 
{
    Write-Host $item["Title"]

    #Copy All Files and Folders from one folder to another
    Copy-PnPFile -SourceUrl $item["Title"] -TargetUrl $TargetFolderURL -SkipSourceFolderName -Force

}

我有一个错误:Copy-PnPFile:找不到文件。

我不知道如何解决这个问题,任何人都可以帮助我吗?

谢谢

标签: powershellsharepointoffice365power-automate

解决方案


SourceUrl 应该是文件服务器的相对 url,使用 FileRef 代替,TargetUrl 应该是 TargetFolderURL +filename

修改代码片段如下:

$SiteURL = "https://Tenant.sharepoint.com/sites/dev"
$TargetFolderURL = "/sites/dev/docs/"
$SitestoCopy = "copy"

Connect-PnPOnline -Url $SiteURL -UseWebLogin

$items = Get-PnPListItem -List $SitestoCopy

Write-Host "Nombre total d'éléments :" $items.Count

ForEach ($item in $items) 
{

    $TargetFileUrl=$TargetFolderURL+$item["FileLeafRef"]
    #Copy All Files and Folders from one folder to another
    Copy-PnPFile -SourceUrl $item["FileRef"] -TargetUrl $TargetFileUrl -SkipSourceFolderName -Force

}

推荐阅读