2
Param
(
 [Parameter (Mandatory= $true)]
 [string] $siteUrl,
 [Parameter (Mandatory= $true)]
 [string] $DocLibName
)


#Connect to SPO
$tenantName= "client"
$username = "[email protected]"
$password = "hashing!" | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$Password


#create view
$ViewName= "Grouped by Team"
$ViewFields = @("DocIcon","LinkFilename","Team", "Modified", "Modified_x0020_By")
$ViewQuery = "<GroupBy Collapse=""TRUE""><FieldRef Name=""Team"" Ascending=""True""/></GroupBy> <OrderBy><FieldRef Name=""LinkFilename"" /></OrderBy>"

#provide view
Connect-PnPOnline -Url $siteUrl -Credentials $cred
Add-PnPView -List $DocLibName -Title $ViewName -Fields $ViewFields -Query $ViewQuery

I'm running this Runbooks/PowerShell script. Somehow this script always runs 3 times in Azure with an exception:

The runbook job was attempted 3 times, but it failed each time. Common reasons that runbook jobs fail can be found here: https://docs.microsoft.com/en-us/azure/automation/automation-troubleshooting-automation-errors

The script works like a charm on my local PowerShell and PowerShell ISE...

Any runbooks hero in the house?

1 Answer 1

3

I had same issue when executing Add-PnPListItem and Add-PnPFile on Azure Runbook. I googled answers and finally found the following threads:

https://github.com/SharePoint/PnP-PowerShell/issues/1541

https://github.com/SharePoint/PnP-PowerShell/issues/918

They suggest a workaround for this issue is assigning output to a variable like below.

$dummy = Add-PnpFile -Path $file -Folder $folder

It works for me. Your issue seems same kind, so it is worth trying. Hope it will help!

1
  • Also had this issue with the cmdlet Set-PnPListItem in module pnp.powershell
    – Andreas
    Commented Nov 23, 2021 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.