Powershell input parameters with runbook

Raj D 576 Reputation points


I'm exploring different options to execute an azure automation runbook written in powershell that has a few input parameters. I have looked at the microsoft documentation but still not clear on how to implement this. Now, how would I pass the input parameters along with the webhook uri to execute the underlying azure automation runbook.


$uri = "https://webhook.us.azure-automation.net/webhooks?token=abc"  
Invoke-WebRequest -Method Post -Uri $uri   
#Input parameter  

Thank you in advance.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
945 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 69,551 Reputation points MVP

    Hi @Raj D ,

    let's start with a simple Automation Runbook with a simple PowerShell script.

    Create a new Automation Runbook and add the following PowerShell script:

        [Parameter(Mandatory = $false)]  
        [object] $WebhookData  
    $Inputs = ConvertFrom-Json $webhookdata.RequestBody  
    Write-Output "Name of VM = $($Inputs.vmName)"  
    Write-Output "Name of ResourceGroup = $($Inputs.rgName)"  


    Create a webhook for the Runbook and save the URL


    Run the following PowerShell script on your computer to start the Azure Automation Runbook with input parameters :

    $webhookURI = '<your-webhook-URI>'  
    $params  = @{  
    vmName ="TestVM1";  
    rgName ="test1-rg"  
    $body = ConvertTo-Json -InputObject $params  
    $response = Invoke-WebRequest -Method Post -Uri $webhookURI -Body $body -UseBasicParsing  

    The output of the Runbook should look like this:



    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten

    4 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Maxim Sergeev 6,556 Reputation points Microsoft Employee

    Hi there,

    To receive data from the client, the runbook supports a single parameter called WebhookData. This parameter defines an object containing data that the client includes in a POST request.

    In this case you need to use and parse a standard variable $WebhookData

     # Payload comes in as a json object so convert the body into PowerShell friendly object.  
    $RequestBody = ConvertFrom-Json $WebhookData.RequestBody  
    # Get the results from the table object  
    $Result =  $RequestBody.data.SearchResult.tables  


    1 person found this answer helpful.

  2. Andreas Baumgarten 69,551 Reputation points MVP

    Hi @Raj D ,

    Here is a different approach: https://learn.microsoft.com/en-us/azure/automation/runbook-input-parameters


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten