Azure / Azure/azure-powershell

Get-AzAutomationScheduledRunbook missing parameters when array

Open
#11,504 5 comments 0 reactions 1 assignee Claimed by @wyunchi-ms View on GitHub
Azure PS Team customer-reported Investigate :mag:
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

## Description
When using Get-AzAutomationScheduledRunbook, for a JobSchedule that contains an array in a parameter, the output of the Parameter property is missing for that specific parameter.

## Steps to reproduce

```powershell

# Define an object that will be used for parameters on the JobSchedule
# This represents an Azure NSG rule that will be created across each subnet defined in the 'nsggroup' property
$object = [pscustomobject]@{ name = "automationjobruntimedata"; rulename = "any_automationjobruntimedata_443"; ports = @(443,80); endpointfqdn = "eus2-jobruntimedata-prod-su1.azure-automation.net"; nsggroup = @("db-nsg","prod-extweb-nsg","prod-nsg","test-nsg","mgmt-nsg") }

# Set up Automation Account variables
$resourceGroupName = "automation-rg"
$automationAccountName = "automationAccount"
$subscriptionid = "REDACTED"
$runbookname = "nsg-interface-update"

$scheduleparams = @{
nsggroup = $object.nsggroup
rulename = $object.rulename
endpointfqdn = $object.endpointfqdn
ports = $object.ports
subscriptionid = $subscriptionid
}
$runbookparams = @{
Name = $runbookname
ScheduleName = "6Hours-$($object.name)"
AutomationAccountName = $automationAccountName
ResourceGroupName = $resourceGroupName
Parameters = $scheduleparams
}
$sched = Get-AzAutomationSchedule -Name "6Hours-$($object.name)" -AutomationAccountName $automationAccountName -ResourceGroupName $resourceGroupName -ErrorAction Ignore

$StartTime = (Get-Date).AddMinutes(10) # Start Time should do the first run in 10 minutes.

New-AzAutomationSchedule -Name "6Hours-$($object.name)" -StartTime $StartTime -HourInterval 6 -AutomationAccountName $automationAccountName -ResourceGroupName $resourceGroupName

Register-AzAutomationScheduledRunbook @runbookparams

# Get the job that we just created
$scheduledjob = Get-AzAutomationScheduledRunbook -Name $runbookname -ScheduleName "6Hours-$($object.name)" -AutomationAccountName $automationAccountName -ResourceGroupName $resourceGroupName
# Find the Parameters for the job
$setparams = (Get-AzAutomationScheduledRunbook -jobscheduleid $scheduledjob.jobscheduleid -AutomationAccountName $automationAccountName -ResourceGroupName $resourceGroupName).Parameters
```
Result is that in the Portal, the parameter is created as an array properly:
![portal](https://user-images.githubusercontent.com/40004712/78583851-9b553680-77f4-11ea-96b8-f836e4e31f13.png)

However, when looking at $setparams, the values for ports and nsggroup are empty:
![setparams](https://user-images.githubusercontent.com/40004712/78585626-65fe1800-77f7-11ea-831d-934a2b8d1eb1.png)

See Debug output below, where the actual REST API call returns JSON containing the parameters, but with additional /r/n line breaks added.

It appears that the conversion of the REST JSON body into a PowerShell Hashtable in Powershell 7 isn't functioning, where it does in PowerShell 5.1 or 6.

## Environment data
This only appears to occur on PowerShell 7; not 6 or 5.1

```
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.18363
Platform Win32NT
```

## Module versions

```powershell
ModuleType Version PreRelease Name
---------- ------- ---------- ----
Script 3.7.0 Az
Script 1.3.6 Az.Automation
```

## Debug output

```
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/4ceb974a-REDACTED/resourceGroups/rgname/providers/Mi
crosoft.Automation/automationAccounts/AutomationAccount/jobSchedules/23e424e0-fe66-450f-b7ff-589aa8fb82be?api-version=2015-1
0-31

Headers:
x-ms-client-request-id : cdc63e1e-8cfd-40aa-95e4-132067eaa080
Accept-Language : en-US

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-request-id : b440e97a-9f13-4dc9-
Strict-Transport-Security : max-age=31536000; includeSubDomains
Server : Microsoft-IIS/10.0
X-AspNet-Version : 4.0.30319
X-Powered-By : ASP.NET
x-ms-ratelimit-remaining-subscription-reads: 11999
x-ms-correlation-request-id : e569aa11-fe6a-4d5e-
x-ms-routing-request-id : NORTHCENTRALUS:20200406T164340Z:e569aa11-fe6a-4d5e-bdd7-75bd0d13baa9
X-Content-Type-Options : nosniff
Date : Mon, 06 Apr 2020 16:43:39 GMT

Body:
{
"id": "/subscriptions/4ceb974a-REDACTED/resourceGroups/rgname/providers/Microsoft.Automation/
automationAccounts/AutomationAccount/jobSchedules/23e424e0-fe66-450f-b7ff-589aa8fb82be",
"type": "Microsoft.Automation/AutomationAccounts/JobSchedules",
"properties": {
"jobScheduleId": "23e424e0-fe66-450f-b7ff-589aa8fb82be",
"runbook": {
"name": "nsg-interface-update"
},
"schedule": {
"name": "6Hours-automationjobruntimedata"
},
"runOn": null,
"parameters": {
"SubscriptionId": "\"047f8a8b-REDACTED\"",
"RuleName": "\"any_automationjobruntimedata_443\"",
"endpointfqdn": "\"eus2-jobruntimedata-prod-su1.azure-automation.net\"",
"nsggroup": "[\r\n \"db-nsg\",\r\n \"prod-extweb-nsg\",\r\n \"prod-nsg\",\r\n \"te
st-nsg\",\r\n \"mgmt-nsg\"\r\n]",
"ports": "[\r\n 443,\r\n 80\r\n]"
}
}
}

DEBUG: AzureQoSEvent: CommandName - Get-AzAutomationScheduledRunbook; IsSuccess - True; Duration - 00:00:01.0278770; Exc
eption - ;
DEBUG: Finish sending metric.
DEBUG: 10:44:20 AM - GetAzureAutomationScheduledRunbook end processing.
DEBUG: 10:44:20 AM - GetAzureAutomationScheduledRunbook end processing.
```

## Error output

No errors encountered

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.