juvchan
juvchan

Reputation: 6245

Test-AzureRmResourceGroupDeployment cmdlet returns Empty when the validation is successful

I use the Azure Powershell cmdlet below to validate both the ARM template json and ARM template params json files.

$result = Test-AzureRmResourceGroupDeployment -ResourceGroupName TestRG -TemplateFile TestARMTemplate.json -ApiVersion TestARMParams.json

I expect the cmdlet to return true (boolean type) if both input arguments are valid.

However, the result is empty.

The documentation is also not clear on the expected response of this cmdlet.

I would like to know whether the response I got is an expected response or not.

Note: I am using Azure PowerShell version 1.5 (June 2016) on Windows 10 machine.

Upvotes: 3

Views: 1684

Answers (2)

Ohad Schneider
Ohad Schneider

Reputation: 38106

Here is a handy function for creating an AggregateException containing all the error information from a PSResourceManagerError

function New-DeploymentResultException([Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResourceManagerError]$error)
{
    $errorMessage = "$($error.Message) ($($error.Code)) [Target: $($error.Target)]"

    if ($error.Details)
    {
        $innerExceptions =  $error.Details | ForEach-Object { New-DeploymentResultException $_ }
        return New-Object System.AggregateException $errorMessage, $innerExceptions
    }
    else 
    { 
        return New-Object System.Configuration.ConfigurationErrorsException $errorMessage
    }
}

Upvotes: 1

Gaurav Mantri
Gaurav Mantri

Reputation: 136126

Looking at the source code for this Cmdlet here, I don't think it returns true or false. It actually returns an object of type List<PSResourceManagerError>. If you do a count on the $result object, it should return you zero if everything's ok.

Upvotes: 5

Related Questions