powershell - 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:找不到文件。
我不知道如何解决这个问题,任何人都可以帮助我吗?
谢谢
解决方案
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
}
推荐阅读
- javascript - vue table 显示数据 v-for v-if
- git - 一次提交更新所有分支
- vim - 执行 :Ex 时如何阻止 Vim 水平拆分窗口
- r - R:R是否自然保留行的顺序
- python - 如何在python中使用模拟json数据库文件
- python - 似乎无法从下拉菜单中选择 - Python Selenium
- ruby-on-rails - 如何在 ruby 代码中使用 Stripe 令牌通过 Stripe::Account.create() 创建帐户?
- javascript - 反应原生应用程序卡在白屏上,没有任何错误
- swiftui - SwiftUI 多个标签垂直对齐
- r - 使用 map 函数从列表中进行子集试验