How to restrict Resources count in GET request in

2019-08-04 10:00发布

问题:

How to filter the resources count in GET Request in AzureRM ?

For an example in List Virtual Machines in an subscription . We get all the Vm's running in an account .

But I need to get 10 VM's alone in ascending or any sorting order . Is there any filter available like that ?

回答1:

If the sorting order does not matter for you, you can filter the resource count for the top 10 VMs in the GET request below:

I've tried the requests below and tweak resource count for filtering and they all worked as expected.

https://management.azure.com/subscriptions/{subscriptionId}/resources?$filter=resourceType eq 'Microsoft.Compute/virtualmachines'&$top=10&api-version={apiVersion}

Sample response is like below:

{
    "value": [
        {
            "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm}",
            "name": "{vm}",
            "type": "Microsoft.Compute/virtualMachines",
            "location": "{location}"
        },
        {
            "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm}",
            "name": "{vm}",
            "type": "Microsoft.Compute/virtualMachines",
            "location": "{location}"
        }
    ]
}

Hope this helps.



回答2:

You could use the following API.

https://management.azure.com/subscriptions/**********/providers/Microsoft.Compute/virtualmachines?api-version=2017-12-01&top=10

Using $top=10 to filter the top 10 result. See this example.