Wednesday, April 2, 2014

Azure CmdLets which do not support ErrorAction WarningAction behaviour

While working on some scripts for an upcoming presentation I noticed some behavioral changes in the Azure CmdLets particularly with the use of the ErrorAction and WarningAction common parameters.  In my case I was using the Add-DomainControllerAndMemberServer.ps1 (available here) and found that it uses the -ErrorAction parameter for error handling when testing if azure services are already provisioned.

What i found is that the Get-AzureVNetSize cmdlet still throws an error when the Virtual Network does not exist even if you supply the ErrorAction parameter.

So running this:
Get-AzureVNetSite -VNetName "mlaveryvnet"

Or this:
Get-AzureVNetSite -VNetName "mlaveryvnet" -ErrorAction SilentlyContinue

Still results in the following error when the virtual network does not exist:

Get-AzureVNetSite : The specified virtual network name was not found: mlaveryvnet
Parameter name: VirtualNetworkName
At line:1 char:9
+ $vNet = Get-AzureVNetSite -VNetName "mlaveryvnet"
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AzureVNetSite], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVNetSiteCommand


Something to be aware of because even though the cmdlet may take the parameters from the command line, it doesn't mean it has been programed to include that functionality.

In my case I had to switch to the Get-AzureVNetConnection cmdlet as it does provide the functionality and as all I was doing was testing if the network exists this works. Your particular case may differ.

Get-AzureVNetConnection -VNetName "mlaveryvnet" -ErrorAction SilentlyContinue