Skip to main content

Notifications

Power Automate - Using Connectors
Unanswered

Azure Automation Create Job Failing

(0) ShareShare
ReportReport
Posted on by 2

I've written a PowerShell script which downloads a file from a URL to the local PC then uploads that file to a SharePoint Online library. Running the script locally works but when I try getting it to run from a runbook triggered by Flows/Power Automate I get the error: Action HTTP failed; Input value wasn't JSON object. This flow is manually triggered and was working before I put the Create Job step in.

 

Screenshots and PowerShell script below, any help is greatly appreciated.

 

Screenshot1

Set Variable: actions('HTTP').outputs.headers.Location

 
Compose: concat('https://api.sendgrid.com/v3/messages/download/',substring(variables('redirect'),63,36))
 
Screenshot2
 
 
Compose 2: replace(replace(body('HTTP_2'),'{"presigned_url":"',''),'"}','')
 
Compose 3: replace(outputs('Compose_2'),'%2F','/')
 
Screenshot 3
 
 
 
PowerShell:
 
Function Download-File() {
    
    param (
        [Parameter(Mandatory=$true)] [string] $url,
        [Parameter(Mandatory=$false)] [SecureString] $secPW
        )

    $fileOut = "C:\temp\testDownload.csv"
    
    
    try {
        #Get download file and write to C:\temp\testDownload.csv
        Invoke-WebRequest -Uri $url -OutFile "C:\temp\testDownload.csv"
        Write-host "Download complete"
        #Set up Credentials
        $user = "me@mysharepointsite.com"
        $PW = "P@ssW0rd!!"
        $secPW = $PW | ConvertTo-SecureString -AsPlainText -Force
        $site = "https://mysharepointsite.sharepoint.com/sites/Test/"
       
        #Write credentials to PSCredential object
        $creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$secPw
        
        #Connect to SharePoint Online
        Connect-PnPOnline -Url $site -Credentials $creds
        #Upload File
        Write-Host "Upload Started"
        Add-PnPFile -Folder "test123" -Path $fileOut
        Write-Host "Upload Completed"
        
    }
    catch {
        write-host -f Red "Download failed: " $_.Exception.Message
    }
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
$url = ""
Download-File -url $url
 
  • mwarner Profile Picture
    mwarner 2 on at
    Re: Azure Automation Create Job Failing

    Hi,

     

    How do I add pictures so they're actually visible when initially posting?

     

    After testing it looks like the script doesn't run in Azure Automate, I cannot find where it is failing.

     

    When I looked at the output from the script it looks like it's doing what I expect it to do up until it's downloaded the file and written it to the stream.

     

    powershell runbook test.PNG

  • Re: Azure Automation Create Job Failing

    Hello,

     

    The screenshots were not visible in your question. Are you able to run the same PowerShell script directly in Azure automation (Azure portal) outside of power automate ? This will help determine if the problem is with running the script through Create Job or specifically when doing it through Power Automate.

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,495

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,822

Leaderboard

Featured topics