pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
985 stars 665 forks source link

Synchronised Commands #2375

Open anthonynhn opened 4 years ago

anthonynhn commented 4 years ago

Reporting an Issue or Missing Feature

To synchronise a set of PnP Powershell commands so that they can run and complete ONE BY ONE in an expected order.

Expected behavior

Like the way Promises are managed and synchronised in PnP JS, please advise how we can ensure that a PnP Powershell command can be called and completed before the next command is triggered.

Actual behavior

No instruction given.

Steps to reproduce behavior

For example, we want to use PnP commands to copy all files in a source library to a destination library, then ensure that the copy is done before we can proceed to run PnP commands to delete files at the source library.

Which version of the PnP-PowerShell Cmdlets are you using? SharePoint Online

What is the version of the Cmdlet module you are running?

Run the commands in the following order:

  1. Copy-PnPFile
  2. Remove-PnPFile

How did you install the PnP-PowerShell Cmdlets?

ghost commented 4 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

danielcecil commented 4 years ago

Hi, this is more of a PowerShell question as the default behaviour in PowerShell is to Continue if an error is received.

Have a look at the ErrorAction common parameter in PowerShell e.g. Copy-PnPFile -ErrorAction Stop as this should prevent the following command(s) from running if an error is received.

You might want to go a step further and check the file has actually been copied using Get-PnPFile command in the new destination.

anthonynhn commented 4 years ago

Hi Daniel, thank you for your reply.

In my above example, copying a large file will take longer time (supposed there is no potential error to catch), and the command Remove-PnPFile can kick in before the copy job is done; as a result, the PnP command(s) will fail to run.

By chaining the commands in a synchronised approach, this problem can be eliminated. Please advise whether we have any work-around to avoid such problem in PnP Powershell ?

Thank you & Regards, Anthony Nguyen.