locked
How to pass complex typed argument in Azure runbook schedule's parameter? RRS feed

  • Question

  • In Azure portal UI,

    I created a simple runbook as follows,

    param (
        [Parameter(Mandatory=$true)][object]$user
    )
    
    Write-Output $user.Name

    And created a schedule for that runbook with "Parameters and run settings" as follows,

    { "Name": "vm1" }

    When run this schedule at specified time, it seems it failed to de-serialize { "Name": "vm1" } as $user object. The result of $user.Name is null.

    I checked the settings of parameters on the schedule by entering to "Parameters View input parameters" in Azure portal UI, it is set by this,

    { \"Name\": \"vm1\" }

    I think, it failed because of escaping of \".

    It has to show like this,

    { "Name": "vm1" }

    I tested it by creating with PowerShell client code,

    $vmParams = '{ "Name": "vm1" }' | ConvertFrom-Json
    $runbookParams = @{"user"=$vmParams}
    Register-AzureRmAutomationScheduledRunbook -AutomationAccountName "testrunbook" -RunbookName "stop_vm" -ScheduleName "Schedule01" -ResourceGroupName "myservice2" -Parameters $runbookParams

    It shows expected results { "Name" : "vm1" } in Azure portal UI.



    Thursday, May 10, 2018 3:06 AM

Answers

  • Change your input parameter to type [PSObject] rather than [object].  That should automatically convert your json input into a PSObject typed object.
    Monday, June 4, 2018 6:00 PM

All replies

  • Change your input parameter to type [PSObject] rather than [object].  That should automatically convert your json input into a PSObject typed object.
    Monday, June 4, 2018 6:00 PM
  • Change your input parameter to type [PSObject] rather than [object].  That should automatically convert your json input into a PSObject typed object.

    It works. Thanks. :)

    Tuesday, June 5, 2018 5:37 AM