PowerShell is a “must-know” for Azure cloud development. Yes, it’s a scripting language, but moreover, it’s an automation engine that can execute complex tasks with minimal effort. The vast majority of Azure administrative functionality is available in PowerShell. Many of the GUI consoles are simply executing PowerShell commands behind the scene.
That said, what do you do when a PowerShell cmdlet presents a vague error message to you?
In the code block below, we invoke the New-AzureRMServiceFabricCluster to provision a secure Service Fabric cluster in an Azure Resource Group.
However, things become a bit dicey when we get the following error message:
If you look closely, it tells you that it is unhappy when executing the New-AzureRmServiceFabricCluster cmdlet, but provides little meaningful detail.
Now, what do you do?
PowerShell supports two optional parameters that can provide information about the execution of the cmdlet:
The -Verbose parameter displays any and all logging entries included by the cmdlet author, such as “Connecting to xyz”.
The -Debug parameter displays any trace code implemented with a Write-Debug statement in the cmdlet, such as dumping the content of a variable.
So, with that in mind, I modify my original script to the following:
Doing so exposes the logging and debugging statements added to cmdlet – which might just shed some light on the problem.
Don’t be surprised if the sheer amount of data is large:
Within this cmdlet, information for each Request and Response are presented:
And, if we continue examining the Debug information, we find the underlying problem:
Note above how the response returns a status code of Forbidden.
Keep in mind that the Logging and Debugging information that you receive will be driven by the richness of the Write-Debug and Write-Verbose that the cmdlet author added, but it can be lifesaver in getting to the bottom of a vague error.
Rob Vettor is a Senior Developer Consultant with Microsoft, helping Microsoft Enterprise customers construct high-quality software. Rob focuses on Azure PaaS, including the Service Fabric and Azure App Services platforms. A former user group leader, 3-time C# MVP and co-author of the book Entity Framework 6 Recipes, Rob is a frequent presenter at technical conferences. Reach out at firstname.lastname@example.org.