Home > Software engineering >  Sharepoint online - MoveFile - pnp.powershell Status Updates
Sharepoint online - MoveFile - pnp.powershell Status Updates

Time:11-12

I'm trying to do folder/files moves from one sharepoint site to another, and I can't seem to get the Receive-PnPCopyMoveJobStatus to work in my powershell script

Right now the only way I can monitor a file/folder move is to monitor the source's recycling bin for changes. I'd like to be able to get progress either on demand, or consistently in an open powershell. Ideally I'd like to see a percentage sign, and even a verbose option.

Here's what I have put together:

#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"
}

referencing: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/receive-pnpcopymovejobstatus?view=sharepoint-ps

I haven't been successful in running this. When I fill in the site names, library names, and actual site, I get a result that looks like it completes, but with no feedback, nor do the files move. So essentially nothing happens.

What does work for the file/folder move is the following:

#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

Any help on correcting this script, or other methods on seeing the progress of Copy or Move operations on SharePoint would be appreciated!

CodePudding user response:

The source url should be like "<document library>/<file name>" Please try following script

$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"
}

CodePudding user response:

Your non-working script contains:

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

Both of these variable values are strings. They don't do anything except exist, and do not cause any commands to run. $jobStatus.JobState will always be null and never zero, because JobState is not a property of a string, so the if condition is never met.

If you want to run the commands, don't write them as strings inside double quotes, but just as they are in the documentation you referred to. You can actually run them, and capture their output, with e.g.

$jobStatus = Receive-PnPCopyMoveJobStatus -Job $Test

You can also just copy and paste the example and update the parameter values (though it seems to have the wrong variable name on the second line, which you've already fixed). You may have further errors once the commands are running, which should provide further diagnostic information. Make sure that you are doing all of connecting, requesting the move, and retrieving the status information in the same script.

  • Related