Troubleshooting Azure Resource Manager (ARM) PowerShell issues

My colleague Neil just did a great article on how to interact with the REST APIs directly.  When working with ARM via PowerShell it is also often useful to understand the actual REST requests that are being sent to the ARM APIs on your behalf.    Thankfully capturing this traffic from PowerShell is relatively simple.  The Azure PowerShell team has done a great job of instrumenting.   By setting the variable $DebugPreference to a value of "Continue" the raw HTTP request and response will be output to the console along with other useful information.   This is standard practice for custom scripts which leverage the Write-Debug CMDlet and the team has continued this tradition with their implementation.

To get started in your PowerShell session you need to change the variable value from "SilentlyContinue" which is the default to "Continue".   This will trigger the verbose output to the console.

 

 PS C:\>$DebugPreference = "Continue"

 

Once I’ve set that if I use any of the ARM CMDlets you’ll see a very verbose log of what is happening including the authentication and raw HTTP request/response.

 

image

 

If I combine this with the PowerShell Start-Transcript CMDlet I can capture the output for my scripts for later review.

 

 $DebugPreference="Continue"
Start-Transcript -Path c:\output.txt

Login-AzureRmAccount
Get-AzureRmStorageAccount

Stop-Transcript