Azure / Azure/azure-powershell
Start-AzAutomationRunbook doesn't output the right error
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
When executing Start-AzAutomationRunbook to execute a runbook, when there's an error, it returns with the message "Invalid runbook parameters." even if the actual HTTP Response's error was different. At least, I saw this behavior when attempting to execute a Runbook in a different subscription than what I had selected.
### Script/Steps for Reproduction
1. You have an environment with two subscription A and B. Subscription B is your default subscription so when you log into AZ, you are automatically logged in and this subscription gets selected.
2. Now, create an Automation Runbook in Subscription A.
3. Login with AZ into Azure, make sure you have subscription B selected and use Start-AzAutomationRunbook cmdlet to run the runbook.
```powershell
Start-AzAutomationRunbook -Name "RunbookName" -Parameters $Params -ResourceGroupName "ResourceGroupName" -AutomationAccountName "AutomationAccountName"
```
### Module Version
```powershell
Get-Module -ListAvailable
PS C:\Program Files\WindowsPowerShellCore> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.0.0 Az.Accounts {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount...}
Script 1.0.0 Az.Automation {Export-AzAutomationDscConfiguration, Export-AzAutomationDscNodeReportContent, Export-AzAutomationRunbook, Get-AzAutomationAccount...}
Manifest 6.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty...}
Manifest 6.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script 2.0.0 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}
PS C:\Program Files\WindowsPowerShellCore>
```
### Environment Data
```powershell
PS C:\Program Files\WindowsPowerShellCore> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.1
PSEdition Core
GitCommitId 6.1.1
OS Microsoft Windows 10.0.16299
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS C:\Program Files\WindowsPowerShellCore>
```
### Debug Output
```
PS C:\Program Files\WindowsPowerShellCore> Start-AzAutomationRunbook -Name "RunScriptonVM" -Parameters $Params -ResourceGroupName "ResourceGroupName" -AutomationAccountName "AutomationAccountName" -verbose -debug
DEBUG: 10:59:54 - StartAzureAutomationRunbook begin processing with ParameterSet 'ByAsynchronousReturnJob'.
Confirm
Continue with this operation?
[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): A
DEBUG: 10:59:55 - using account id 'UserID@Domain.net'...
DEBUG: [Common.Authentication]: Authenticating using Account: 'UserID@Domain.net', environment: 'AzureCloud', tenant: 'TenantId'
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/SubscriptionId/resourceGroups/ResourceGroupName/providers/Microsoft.Automation/automationAccounts/AutomationAccountName/runbooks/RunScriptonVM?api-version=2015-10-31
Headers:
x-ms-client-request-id : 87a441ed-d260-4c56-8cd9-f7fce3ee6fc7
Accept-Language : en-US
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
NotFound
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-request-id : fbdfb0cb-9378-4a02-b60b-f2159bf3515a
x-ms-correlation-request-id : fbdfb0cb-9378-4a02-b60b-f2159bf3515a
x-ms-routing-request-id : CANADACENTRAL:20181226T135956Z:fbdfb0cb-9378-4a02-b60b-f2159bf3515a
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Date : Wed, 26 Dec 2018 13:59:55 GMT
Body:
{
"error": {
"code": "ResourceGroupNotFound",
"message": "Resource group 'ResourceGroupName' could not be found."
}
}
Start-AzAutomationRunbook : Invalid runbook parameters.
At line:1 char:1
+ Start-AzAutomationRunbook -Name RunScriptonVM -Parameters $Params -Re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Start-AzAutomationRunbook], ArgumentException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.StartAzureAutomationRunbook
DEBUG: AzureQoSEvent: CommandName - Start-AzAutomationRunbook; IsSuccess - False; Duration - 00:00:02.0584922; Exception - System.ArgumentException: Invalid runbook parameters.
at Microsoft.Azure.Commands.Automation.Common.AutomationPSClient.ProcessRunbookParameters(String resourceGroupName, String automationAccountName, String runbookName, IDictionary parameters)
at Microsoft.Azure.Commands.Automation.Common.AutomationPSClient.StartRunbook(String resourceGroupName, String automationAccountName, String runbookName, IDictionary parameters, String runOn)
at Microsoft.Azure.Commands.Automation.Cmdlet.StartAzureAutomationRunbook.AutomationProcessRecord()
at Microsoft.Azure.Commands.Automation.Cmdlet.AzureAutomationBaseCmdlet.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 10:59:57 - StartAzureAutomationRunbook end processing.
DEBUG: 10:59:57 - StartAzureAutomationRunbook end processing.
```
Contributor guide
Assessment
This issue has not been assessed yet.