Start-AzAutomationRunbook passing python parameters out of order and breaks script

Kenneth Huddleston 41 Reputation points
2022-12-07T20:24:30.91+00:00

I have a powershell runbook in Automation with the following workflow:

1) Authenticate to Azure Resources
2) Retrieve creds from vaults
3) Call Python runbook (in same automation account) using those creds

The first two steps work perfectly. The isolated Python script (when fed the correct data) works perfectly. Step 3 fails, because when I pass a dictionary with the 4 params required by the script - they are passed in the wrong order. So my execution looks something like this:

$params = @{"Key1"="ValueForPosition1";"Key2"="ValueForPosition2";"Key3"="ValueForPosition3";"Key4"="ValueForPosition4"}
Start-AzAutomationRunbook -AutomationAccountName "Contoso17" -Name "RunbkPy01" -ResourceGroupName "ResourceGroup01" -Parameters $params

This fails because on line 2, the params are passed out of order (presumably, since dictionaries are inherently unordered). How can I get around this?

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

Accepted answer
  1. Monalla-MSFT 13,071 Reputation points Moderator
    2022-12-13T16:31:42.49+00:00

    @Kenneth Huddleston - Thanks again for raising the doc update request on this issue.

    We have updated the documentation https://github.com/Azure/azure-powershell/issues/20408.

    Hope this helps. and please feel free to reach out if you have any further questions.

    ------------------------------------------------------------------

    If the above response was helpful, please feel free to "Accept as Answer" and "Upvote" the same so it can be beneficial to the community.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Kenneth Huddleston 41 Reputation points
    2022-12-07T20:30:45.933+00:00

    I found the solution using this article: https://devblogs.microsoft.com/scripting/use-powershell-to-create-ordered-dictionary/. All that was needed is to define the dictionary as ordered. So, instead of dict = @{}, it would be dict = [ordered]@{}.

    It should have been obvious, in hind-sight. My own post called out the need for the dictionary to be 'ordered'. lol

    I would like to suggest that this nugget of information be added to the MS documentation here: https://learn.microsoft.com/en-us/powershell/module/az.automation/start-azautomationrunbook?view=azps-9.2.0 ?

    Specifically, in step 2 of running a Python Automation Runbook - an example is given of how to pass parameters. This 'ordered' accelerator is not used in the example, and I think that contributed to my confusion. Just a suggestion.


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.