azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

problem with aggregation?

Open sarah026 opened this issue 7 years ago • 1 comments

Hi

Please validate that the aggregate syntax is correct. Trying to run your command from powershell, it seems to fail

PS: az policy state list --apply "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numStates))"
az : ERROR: (InvalidApplyInQueryString) 'with' expected at position 116 in 'groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate( as numStates))'.
At line:1 char:1
+ az policy state list --apply "groupby((policyAssignmentId, policySetD ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (ERROR: (Invalid...s numStates))'.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError 


This one using AzureRM works fine... I think I'll revert back, as even the outcome is displayed much better than having to process json file. Get-AzureRmPolicyState -Filter "IsCompliant eq false" -Apply "groupby((PolicyAssignmentId, PolicySetDefinitionId, PolicyDefinitionReferenceId, PolicyDefinitionId), aggregate($count as NumStates))" -OrderBy "NumStates desc" `

Thanks


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

sarah026 avatar Dec 23 '18 19:12 sarah026

Since you are in powershell, the $count will be interpreted as a variable and becomes an empty string, so avoid such behavior, you need to use single quotes. My PR #8668 will clarify this

yugangw-msft avatar Mar 01 '19 03:03 yugangw-msft