azure cli provides different results from portal UI

Kerwin, Eric 1 Reputation point
2022-04-08T16:02:52.687+00:00

When running the command:

    az resource list --resource-group RESOURCE-GROUP --query "length([])"

I get 60.

However, when I navigate to the RESOURCE-GROUP in the portal UI, I see 61 results, which is what I expect. This has happened a few times and often, after a variable delay, eventually the cli returns 61.

What is the explanation for the differences? Is the cli only providing updated results after a certain delay?

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Siva-kumar-selvaraj 15,721 Reputation points
    2022-04-11T06:22:23.237+00:00

    Hello @Kerwin, Eric ,

    Thanks for reaching out.

    I was getting below error when I run az resource list --resource-group test --query "length([])" from client machine where I installed Az module.

    Error from client machine:
    191715-untitled.png

    However, I was able to get appropriate count without any delay by using below combination from Azure CLI

    az resource list --resource-group sivaRG --query "length(@)"  
    az resource list --resource-group sivaRG --query "length([])"  
    az resource list --resource-group sivaRG --query "length([*])"  
    az resource list --resource-group sivaRG --query "[*].name | length(@)"  
    az resource list --resource-group sivaRG --query "[*].name | length([])"  
    az resource list --resource-group sivaRG --query "[*].name | length([*])"  
    

    191647-image.png

    Therefore, would request you to try above combination to see if you see any discrepancy also could you try using following filter to see if you get appropriate count az resource list --resource-group sivaRG --query "[*].name ?

    Hope this helps. Thanks.

    -----
    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.