PnP Powershell upload failure

Nishad Manampatta 25 Reputation points
2020-07-17T02:51:33.017+00:00

I am trying to achieve the following using Azure Automate Run book

  1. Download few CSV's
  2. Upload them to Sharepoint.

While it works for one file, no matter how differently i try it fails when i add more than one file.

Behavior: Run book works well connects to SPO , uploads file successfully and then it stops. 3 times it uploads same file and then get below exception.
Exception: The runbook job was attempted 3 times, but it failed each time.

I tried

  • Same script locally and it works fine
  • Followed the instruction as per this documentation https://learn.microsoft.com/en-us/azure/automation/automation-troubleshooting-automation-errors
  • Tried garbage collection
  • Tried removing each file after upload, tried clearing variables.
  • File size is less than 10 KB's and is within the limits specified by MS.
  • Tried within a loop, without loop ( just download two files and upload them one by one )
  • Add-PnPFile -Path .\Emailappuserdetail.csv -Folder $Customer -Connection $session2

Based on various tests that i have done, i feel this issue occurs after first file upload, and i am hitting some limits, which i dont know. Enabled verbose logging, and tried all other options including log analytics to see why it is failing.
Has anyone faced this? any help would be appreciated.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,147 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,914 questions
{count} votes

Accepted answer
  1. Baker Kong-MSFT 3,796 Reputation points
    2020-07-20T05:01:02.51+00:00

    Hi nish-1910,

    When i run "Add-PnPFile" cmdlet in Azure runbook, i am able to reproduce the issue like below:

    12946-0.png

    At last i fix it via following script:

    $PSCredentials=Get-AutomationPSCredential -Name 'sharepointlogincred'
    
    $con = Connect-PnPOnline -Url 'https://xxx.sharepoint.com/sites/s01' -Credentials $PSCredentials
    
    # first file
    $filepath= $env:temp+ "\file-example_PDF_500_kB.pdf"
    Write-Output $filepath
    
    Invoke-WebRequest -Uri "https://file-examples-com.github.io/uploads/2017/10/file-example_PDF_500_kB.pdf" -OutFile $filepath
    
    $addfile = Add-PnPFile -Path $filepath -Folder "Shared Documents"
    
    
    # second file
    $filepath01= $env:temp+ "\file_example_PPT_500kB.ppt"
    Write-Output $filepath01
    
    Invoke-WebRequest -Uri "https://file-examples-com.github.io/uploads/2017/08/file_example_PPT_500kB.ppt" -OutFile $filepath01
    
    $addfile = Add-PnPFile -Path $filepath01 -Folder "Shared Documents"
    
    # 3rd file
    $filepath02= $env:temp+ "\file_example_PNG_1MB.png"
    Write-Output $filepath02
    
    Invoke-WebRequest -Uri "https://file-examples-com.github.io/uploads/2017/10/file_example_PNG_1MB.png" -OutFile $filepath02
    
    $addfile = Add-PnPFile -Path $filepath02 -Folder "Shared Documents"
    

    Below thread shared some tips that might be helpful to this issue:

    Best Regards, Baker Kong


0 additional answers

Sort by: Most helpful