Search code examples
azurepowershellazure-powershell

Azure powershell Get-AzAutomationWebhook: Parameter set cannot be resolved


When I attempt getting a webhook by name, running this command against Azure powershell

Get-AzAutomationWebhook -Name "WhName" -RunbookName "RB_Name" -ResourceGroupName "rgname" -AutomationAccountName "MyAutomationAccount"

I get the following error.

Get-AzAutomationWebhook: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided

and it works fine, if I remove the -Name parameter

Get-AzAutomationWebhook -RunbookName "RB_Name" - ResourceGroupName "rgname" -AutomationAccountName "MyAutomationAccount"

What is the problem here? why can't it work with the -Name parameter as documentation says?


Solution

  • I also received the same error as you when I tried in my environment.

    enter image description here

    After a workaround on your issue, I figured it out that passing both runbook name and name parameters creating a conflict inside the runbook. Because webhooks will already be assigned to specific runbooks.

    Moreover, we are already trying to access the webhook by executing code from a runbook itself, there is no need to provide a separate runbookName parameter. Simply give a Name parameter (Webhook Name) including the automation account and resource group.

    As detailed above, I tried to execute the command in below format and was able to retrieve the webhook details successfully as shown.

    Get-AzAutomationWebhook -Name "newwebhook" -ResourceGroupName "<Resourcegroup>" -AutomationAccountName "newauto"
    

    Output:

    enter image description here

    Alternatively, if you want to retrieve the webhook only by checking the runbook name, use below script.

    $runbooklist = (Get-AzAutomationRunbook -AutomationAccountName "newauto" -ResourceGroupName "<resourcegroup>").Name
    if($runbooklist -eq "newrunbook"){
    Get-AzAutomationWebhook -Name "newwebhook" -ResourceGroupName "<resourcegroup>" -AutomationAccountName "newauto"
    }