0
votes

I'm trying to create a VM using below cmdlet in Azure powershell.

New-AzureRmResourceGroupDeployment -Name VmDeployment -ResourceGroupName ABC `
  -TemplateFile "C:\Templates\template.json" `
  -TemplateParameterFile "C:\Templates\parameters.json"

This cmdlet seems to work for most of the time , but sometimes gives the below error.

New-AzureRmResourceGroupDeployment : An error occurred while sending the request.
At line:1 char:1
+ New-AzureRmResourceGroupDeployment -Name VmDeployment1 -ResourceGroup ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureRmResourceGroupDeployment], HttpRequestException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet.

This error meesage doesn't have any relevant information as to why exactly this is failing.

I try to run the cmdlet for few times and it works again. I don't seem to understand why this doesn't work sometimes even though there is no change in the script.

There are few other cmdlets which has the same issue. But for example sake I have mentioned only one.

Any inputs are highly appreciated.Thanks

1
if you say several unrelated cmdlets are throwing that then its your setup for sure4c74356b41
@4c74356b41 ,When I run this command individually also throws the same error. Can you also explain, what do you mean by problem in setup?CrazyCoder
means something is wrong with your particular machine. try reinstalling azure powershell4c74356b41

1 Answers

0
votes

Some of the issues with New-AzureRmResourceGroupDeployment cmdlets, sometimes it couldn't give a proper error message.

So as a workaround you should try to like 4c74356b41 mentioned in his command reinstalling (or) updating Azure PowerShell modules.

Also, another option is to use $DebugPreference="Continue" before executing the New-AzureRmResourceGroupDeployment

This will determine how PowerShell responds to debugging messages generated by a script, cmdlet or provider, or by a Write-Debug command at the command line

E.g, This will give some details error message like below

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

Status Code:
NotFound

Headers:
Pragma                        : no-cache
x-ms-failure-cause            : gateway
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-request-id               : 65972d3e-495e-41fd-84fd-9b068c62df22
x-ms-correlation-request-id   : 65972d3e-xx-41fd-84fd-xx
x-ms-routing-request-id       : xxx:xxx:65972d3e-xx-41fd-84fd-xx
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Tue, 04 Sep 2018 02:45:49 GMT

Body:
{
  "error": {
    "code": "ResourceGroupNotFound",
    "message": "Resource group 'test' could not be found."
  }
}

You could find the similar issue in github