SharePoint Online-MoveFile-pnp.PowerShell状态更新

3pvhb19x  于 2022-11-10  发布在  Shell
关注(0)|答案(2)|浏览(159)

我正在尝试将文件夹/文件从一个SharePoint站点移动到另一个站点,但似乎无法在PowerShell脚本中使用Receive-PnPCopyMoveJobStatus
目前,我监控文件/文件夹移动的唯一方法是监控源的回收站是否有变化。我希望能够按需取得进展,或者在开放的PowerShell中持续取得进展。理想情况下,我希望看到百分比符号,甚至是详细的选项。
以下是我的总结:


# Config Variables

$SiteURL = "https://<site>.sharepoint.com/
$SourceFolderURL= "sites/<site name>/<document library name>/<Folder or file location>"
$TargetFolderURL = "sites/<site name>/<document library name>"

# Connect to PnP Online

Connect-PnPOnline -Url $SiteURL -interactive

# Sharepoint Copy/Move operation feedback

$Test = "Move-PnPFile -SourceUrl $SourceFolderURL -TargetUrl $TargetFolderURL -Overwrite -noWait"
$jobStatus = "Receive-PnPCopyMoveJobStatus -Job $Test"

if($jobStatus.JobState -eq 0)
{
  Write-Host "Job finished"
}

参考文献:https://learn.microsoft.com/en-us/powershell/module/sharepoint-pnp/receive-pnpcopymovejobstatus?view=sharepoint-ps
我一直没有成功地经营过这个公司。当我填写站点名称、库名和实际站点时,我得到的结果看起来像是完成了,但没有反馈,文件也没有移动。因此,基本上什么都不会发生。
以下是对文件/文件夹移动有效的方法:


# Config Variables

$SiteURL = "https://<site>.sharepoint.com/"
$SourceFolderURL= "sites/<site name>/<document library>/<folder name>"
$TargetFolderURL = "sites/<site name>/<document library>"

# Connect to PnP Online

Connect-PnPOnline -Url $SiteURL -interactive

# sharepoint online powershell move folder

Move-PnPFile -SourceUrl $SourceFolderURL -TargetUrl $TargetFolderURL -overwrite 

# Read more: https://www.sharepointdiary.com/2017/06/how-to-move-folder-in-sharepoint-online.html#ixzz7Bkp822M1

任何有关更正此脚本的帮助,或查看在SharePoint上复制或移动操作的进度的其他方法,都将不胜感激!

y1aodyip

y1aodyip1#

源URL应类似于"<document library>/<file name>"请尝试以下脚本

$SiteURL = "https://<site>.sharepoint.com/sites/<sitesname>
$SourceFolderURL= "<document library name>/<file name>"
$TargetFolderURL = "<document library name>/<target file name>"

$job = Move-PnPFile -SiteRelativeUrl $SourceFolderURL -TargetUrl $TargetFolderURL -Overwrite
$jobStatus = Receive-PnPCopyMoveJobStatus -Job $result
if($jobStatus.JobState == 0)
{
  Write-Host "Job finished"
}
uujelgoq

uujelgoq2#

您的非工作脚本包含:

$Test = "Move-PnPFile -SourceUrl $SourceFolderURL -TargetUrl $TargetFolderURL -Overwrite -noWait"
$jobStatus = "Receive-PnPCopyMoveJobStatus -Job $Test"

这两个变量值都是字符串。它们除了EXIST之外什么都不做,并且不会导致任何命令运行。$jobStatus.JobState将始终为空且不为零,因为JobState不是字符串的属性,因此永远不会满足if条件。
如果您想要运行这些命令,请不要将它们写成双引号内的字符串,而要像您引用的文档中那样写它们。您可以实际运行它们,并捕获它们的输出,例如

$jobStatus = Receive-PnPCopyMoveJobStatus -Job $Test

您还可以复制和粘贴示例并更新参数值(尽管第二行似乎有错误的变量名称,您已经修复了这个问题)。运行命令后,您可能会遇到更多错误,这应该会提供进一步的诊断信息。确保在同一脚本中执行连接、请求移动和检索状态信息的所有操作。

相关问题