Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Azure Powershell : Operation returned an invalid status code 'BadRequest'

While working on few Azure Powershell scripts I was keep receiving an error 'BadRequest' whenever I was trying to create a new resource in Azure. I kept on trying to resolve an error but didn't find any proper solution to it. Initially the message was not much friendly so to dig down further I went through Get-Help of the cmdlet, tried debugging but I was not able to go to any conclusion to resolve the issue.

Microsoft Azure Powershell az module automation account New-AutomationAccount Name Location ResourceGroupName Operation returned in invalid status code 'BadRequest' errorresponseExeption.png

New-AzAutomationAccount : Operation returned an invalid status code 'BadRequest'
At line:1 char:1
+ New-AzAutomationAccount -Name $automationAccount -Location $location  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzAutomationAccount], ErrorResponseException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.NewAzureAutomationAccount

In the next attempt to troubleshoot further I tested and tried to create a new Automation Account on the Azure Portal, then I came to know the Name of Automation Account which I was using has some restrictions and Azure has some strict naming convention guidelines. The name can contain only letters, numbers, and hyphens. The name must start with a letter, and it must end with a letter or a number. The account name length must be from 6 to 50 characters.

Microsoft Azure Portal Add automation account dsc desired state configuration powershellk badrequest powershell devops.png

I tried azure PowerShell New-AzAutomationAccount with proper parameter arguments convention again as defined by Azure, command execution was successful. (Note: I even had mistyped location and it was giving same BadRequest error).

Microsoft Azure Portal Automation account resource group location azure management automation models encryptionporperties powershell az modules error.png

Useful Commands
Create key vault and secrets with access policies in Microsoft Azure
Working With Azure Key Vault Using Azure PowerShell and AzureCLI
Use Key Vault secret identifier url to get the secret value using Powershell
Use a Azure VM system assigned managed identity to access Azure Key Vault
Create an Azure App registrations in Azure Active Directory using PowerShell & AzureCLI
Get started and configure with certificate-based authentication in Azure
Create a Virtual machine on Microsoft Azure
PowerShell List All Azure Resverations
Powershell get the list of Azure Reservations Virtual Machines instances
Get the list Azure Reservation Catalog with PowerShell and AzureCLI

Go Back

Comment

Blog Search

Page Views

5937983

Follow me on Blogarama