Debugging Azure PowerShell with Activity Log

I got the following error message in PowerShell, as I was trying to create an Azure virtual network with multiple subnets by running New-AzureRMVirtualNetwork


New-AzureRmVirtualNetwork : Cannot parse the request.
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 'ac4d152b-3cbb-4087-a5b9-ef4554444334'

This error message is too vague and need more information. So where do I look?

There are two options.

1) The long and manual option

Go to Azure Portal > the target Resource Group > Activity Log
From the error message output, copy the OperationID and paste into the search box
Click Apply
Click on the resulting log item
Click on JSON tab, search within text by the operation ID
DebugAzurePowerShell-3DebugAzurePowerShell-4In the “statusMessage”, I scroll to the right and I find the detailed error message in the “statusMessage” field:
“.. has two child resources with the same name (frontendSubnet)”

2) The quick and scripted option

Add the –Debug switch to the line of PowerShell
You will get more information and even the detailed error message.

My issue was that I had multiple subnets with the same name due to cut and paste of reusing commandlet lines.

If you still want to see the JSON details in the Activity Log using Azure PowerShell, you can use the commandlet Get-AzureRMLog

So by getting the correlation ID from the x-ms-correlation-request-id HTTP header in the debug output, you pass it as a parameter as follows:

Get-AzureRmLog -CorrelationId '6119fdb9-1809-4b86-9ae0-415f47f684af'

By updating my PowerShell script as follows and issue is resolved.

$wafSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name wafSubnet -AddressPrefix ""
$webSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name webSubnet -AddressPrefix ""
$dataSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name dataSubnet -AddressPrefix ""
$batchSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name batchSubnet -AddressPrefix ""
$gatewaySubnet = New-AzureRmVirtualNetworkSubnetConfig -Name 'GatewaySubnet' -AddressPrefix ""


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s