Forum Discussion
antoniobriones
Aug 31, 2019Copper Contributor
Random issues with Pnp Powershell in Azure Runbooks
Hi everyone, we're facing random issues when running PnP powershell from Azure runbooks when several instances of the same runbook run concurrently. The scenario We have several of runbooks, the...
Thomas Berman
Sep 04, 2019Iron Contributor
Hi Antonio,
I've had some issues with running PnP PowerShell in Azure Automation Runbooks before - and apparently some others have as well. Here's a thread on the topic that might cover some of your issues:
https://github.com/SharePoint/PnP-PowerShell/issues/1541
As you can see, Erwin van Hunen himself recommends
Notice that I added -ReturnConnection to Connect-PnPOnline and specified the -Connection parameter on Add-PnPListItem. Normally this is not needed, but in some cases in Azure the connections can be shared between script instances, causing conflicts. Using a combination of -ReturnConnection and -Connection on the cmdlets you can isolate the connection to this specific script.
Another tip that I've implemented (which one of the commenters mentions) which has solved most of my issues is to always capture the return value of your commands even if you don't need them in your script, for example:
$newSite = New-PnPSite -Type....
Rather than simply:
New-PnPSite -Type...
Hope this helps you out