Why is my Azure Runbook failing when triggered from a Power Automate flow

Rick Lister 0 Reputation points
2023-12-03T17:12:16.3966667+00:00

I have an Azure Automation Runbook. It is a PnP PowerShell script which copies a SharePoint site template using the
Get-PnPSiteTemplate cmdlet and then deploys this using the Invoke-PnPSiteTemplate over a newly created, Power Automate created SharePoint site.

In testing the Runbook, all works fine. The script runs, the site template is copied and deployed to the new SharePoint site. (The GetNodeByID error is expected)
User's image

However, when the Azure Runbook is triggered via Power Automate the runbook fails, with an error when trying to create the template: The remote server returned an error: (404) Not Found.
And then an error when trying to Invoke the template: File not found
Rubook_viaFlow

I've rebuilt the runbook, deleted the Azure Job from Power Automate and re-connected it. Nothing seems to work. I have various runbooks which do the same thing on other tenants and this has never occurred. Can anyone help as to what may be be issue?

The code is below:

# Dynamic Parameters, will be passed from Flow
param(
  [parameter(Mandatory=$true)]
  [string]$SiteTemplateURL = "https://xxxxx.sharepoint.com/sites/ecfd-projsitetemplate",
  [parameter(Mandatory=$true)]
  [string]$ApplyTemplatetoURL = "https://xxxxx.sharepoint.com/sites/sitetemplatetest"
)
$libraryName = "Documents"

#Begin provisioning
Set-PnPTraceLog -On -Level Debug
Write-Output "Process to provision site begins. Connecting to template site: " $SiteTemplateURL
Connect-PnPOnline -Url $SiteTemplateURL -ManagedIdentity
Write-Output "Creating template... "
$getTemplate = Get-PnPSiteTemplate -out template.pnp
# Connect to destination site for applying the package or site template
Connect-PnPOnline -Url $ApplyTemplatetoURL -ManagedIdentity
Write-Output "Deploying template on: " $ApplyTemplatetoURL
Invoke-PnPSiteTemplate .\template.pnp
# Remove duplicated Quick Launch links
Remove-PnPNavigationNode -Identity 2002 -Force
Remove-PnPNavigationNode -Identity 1033 -Force
Remove-PnPNavigationNode -Identity 2036 -Force
Remove-PnPNavigationNode -Identity 2037 -Force
Remove-PnPNavigationNode -Identity 2038 -Force
Remove-PnPNavigationNode -Identity 2039 -Force
Remove-PnPNavigationNode -Identity 2040 -ForceRemove-PnPNavigationNode -Identity 1034 -Force
Write-Output "Duplicate links removed"

# Remove Shared Documents Library
If(Get-PnPList -Identity $libraryName)
{
    #sharepoint online powershell to delete library
    Remove-PnPList -Identity $libraryName -Recycle -Force
    Write-Output "Library '$libraryName' Deleted Successfully!"
}
Else
{
    Write-Output "Could not find Library '$libraryName'"
}
Write-Output "Site Provisioned!"

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,368 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.