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

Get-AzureRmVM fails to follow NextLink

Open TrickyTic opened this issue 10 years ago • 5 comments

Cmdlet(s)

Get-AzureRmVm

PowerShell Version

4.0

Module Version

AzureRm.Compute 2.3.0

OS Version

6.3.9600.16406

Description

Get-AzureRmVm returns only the first 50 virtual machines. The cmdlet attempts to follow NextLink but appears to receive an empty body reply.

Debug Output

PS C:\PowerShell> get-azurermvm
DEBUG: 13:38:56 - GetAzureVMCommand begin processing with ParameterSet 'ListAllVirtualMachinesParamSet'.
DEBUG: 13:38:56 - using account id '[email protected]'...
DEBUG: [Common.Authentication]: Authenticating using Account: '[email protected]', environment: 'AzureCloud', tenant: '40ef5872-310e-441c-YYYY-YYYYYYYYYYYY'
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56:  - TokenCache: Deserialized 1 items to token cache.
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56: 21291e39-bbbc-4390-YYYY-YYYYYYYYYYYY - AcquireTokenHandlerBase: === Token Acquisition started:
 Authority: https://login.microsoftonline.com/40ef5872-310e-441c-YYYY-YYYYYYYYYYYY/
 Resource: https://management.core.windows.net/
 ClientId: 1950a258-227b-4e31-YYYY-YYYYYYYYYYYY
 CacheType: Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache (1 items)
 Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 11/29/2016 13:38:56: 21291e39-bbbc-4390-YYYY-YYYYYYYYYYYY - TokenCache: Looking up cache for a token...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56: 21291e39-bbbc-4390-YYYY-YYYYYYYYYYYY - TokenCache: An item matching the requested resource was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 11/29/2016 13:38:56: 21291e39-bbbc-4390-YYYY-YYYYYYYYYYYY - TokenCache: 6.74415269333333 minutes left until token in cache expires
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56: 21291e39-bbbc-4390-YYYY-YYYYYYYYYYYY - TokenCache: A matching item (access token or refresh token or both) was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56: 21291e39-bbbc-4390-YYYY-YYYYYYYYYYYY - AcquireTokenHandlerBase: === Token Acquisition finished successfully. An access token was
retuned:
 Access Token Hash: hJtK77Kn8n2s/NLjJ6K/ZLAoe+wTbqPl+??????????=
 Refresh Token Hash: 7ghuBP5H1QhR0xD27ALA/sErMgA5cnZVj??????????=
 Expiration Time: 11/29/2016 13:45:40 +00:00
 User Hash: NIwAG0nlvx4LULaCWrL0o9jIGNCuUdGRp??????????=

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56:  - TokenCache: Serializing token cache with 1 items.
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56: 07b40d85-3082-440c-YYYY-YYYYYYYYYYYY - AcquireTokenHandlerBase: === Token Acquisition started:
 Authority: https://login.microsoftonline.com/40ef5872-310e-441c-YYYY-YYYYYYYYYYYY/
 Resource: https://management.core.windows.net/
 ClientId: 1950a258-227b-4e31-YYYY-YYYYYYYYYYYY
 CacheType: Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache (1 items)
 Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 11/29/2016 13:38:56: 07b40d85-3082-440c-YYYY-YYYYYYYYYYYY - TokenCache: Looking up cache for a token...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56: 07b40d85-3082-440c-YYYY-YYYYYYYYYYYY - TokenCache: An item matching the requested resource was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 11/29/2016 13:38:56: 07b40d85-3082-440c-YYYY-YYYYYYYYYYYY - TokenCache: 6.744136025 minutes left until token in cache expires
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56: 07b40d85-3082-440c-YYYY-YYYYYYYYYYYY - TokenCache: A matching item (access token or refresh token or both) was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:56: 07b40d85-3082-440c-YYYY-YYYYYYYYYYYY - AcquireTokenHandlerBase: === Token Acquisition finished successfully. An access token was
retuned:
 Access Token Hash: hJtK77Kn8n2s/NLjJ6K/ZLAoe+wTbqPl+??????????=
 Refresh Token Hash: 7ghuBP5H1QhR0xD27ALA/sErMgA5cnZVj??????????=
 Expiration Time: 11/29/2016 13:45:40 +00:00
 User Hash: NIwAG0nlvx4LULaCWrL0o9jIGNCuUdGRp??????????=

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/providers/Microsoft.Compute/virtualMachines?api-version=2016-03-30

Headers:
x-ms-client-request-id        : 21b055c9-dcfc-47c6-YYYY-YYYYYYYYYYYY
accept-language               : en-US

Body:


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-served-by                : 71d495ee-920b-4e8f-bd25-3df17b1f47bc_131239898916350284
x-ms-request-id               : 93dae6e5-1837-4f72-YYYY-YYYYYYYYYYYY
Cache-Control                 : no-cache
Server                        : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 14929
x-ms-correlation-request-id   : 04dd7c37-0956-4156-YYYY-YYYYYYYYYYYY
x-ms-routing-request-id       : EASTUS2:20161129T133856Z:04dd7c37-0956-4156-YYYY-YYYYYYYYYYYY
Date                          : Tue, 29 Nov 2016 13:38:55 GMT

Body:
{
  "value": [
    {
      "properties": {
        "vmId": "07535d45-7698-4002-YYYY-YYYYYYYYYYYY",
        "hardwareProfile": {
          "vmSize": "Basic_A3"
        },
        "storageProfile": {
          "osDisk": {
            "osType": "Windows",
            "name": "ABCDEaps00087_OS_Disk",
            "createOption": "FromImage",
            "image": {
              "uri": "https://portalxxxxxxxxxxxxxxxx.blob.core.windows.net/vhd-images/MYCOMPANY_Server_2012_R2.vhd"
            },
            "vhd": {
              "uri": "https://portalxxxxxxxxxxxxxxxx.blob.core.windows.net/vhds/ABCDEaps00087.vhd"
            },
            "caching": "ReadWrite"
          },
          "dataDisks": []
        },
        "osProfile": {
          "computerName": "ABCDEaps00087",
          "adminUsername": "operations",
          "windowsConfiguration": {
            "provisionVMAgent": true,
            "enableAutomaticUpdates": true
          },
          "secrets": []
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id":
"/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/resourceGroups/mycompany_ABCDE_CORE/providers/Microsoft.Network/networkInterfaces/ABCDEaps00087_NIC_Internal"
            }
          ]
        },
        "diagnosticsProfile": {
          "bootDiagnostics": {
            "enabled": true,
            "storageUri": "https://portalxxxxxxxxxxxxxxxx.blob.core.windows.net/"
          }
        },
        "licenseType": "Windows_Server",
        "provisioningState": "Succeeded"
      },
      "resources": [
        {
          "id":
"/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/resourceGroups/mycompany_ABCDE_CORE/providers/Microsoft.Compute/virtualMachines/ABCDEaps00087/extensions/BGInfo
"
        },
        {
          "id":
"/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/resourceGroups/mycompany_ABCDE_CORE/providers/Microsoft.Compute/virtualMachines/ABCDEaps00087/extensions/JoinAD
"
        },
        {
          "id":
"/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/resourceGroups/mycompany_ABCDE_CORE/providers/Microsoft.Compute/virtualMachines/ABCDEaps00087/extensions/VMSnap
shot"
        }
      ],
      "type": "Microsoft.Compute/virtualMachines",
      "location": "eastus",
      "id": "/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/resourceGroups/mycompany_ABCDE_CORE/providers/Microsoft.Compute/virtualMachines/ABCDEaps00087",
      "name": "ABCDEaps00087"
    },


---8<----- Server details elided for brevity ------------>8---


    {
      "properties": {
        "vmId": "fdc99098-dfbb-45ff-YYYY-YYYYYYYYYYYY",
        "hardwareProfile": {
          "vmSize": "Basic_A2"
        },
        "storageProfile": {
          "osDisk": {
            "osType": "Windows",
            "name": "ABCDEdbs00063-ABCDEdbs00063-0-201608311303530872",
            "createOption": "Attach",
            "vhd": {
              "uri": "https://portalxxxxxxxxxxxxxxxx.blob.core.windows.net/vhds/ABCDEdbs00063-ABCDEdbs00063-2016-8-31-9-3-48-311-0.vhd"
            },
            "caching": "ReadWrite"
          },
          "dataDisks": [
            {
              "lun": 0,
              "name": "ABCDEdbs00063-ABCDEdbs00063-0-201609071313410260",
              "createOption": "Attach",
              "vhd": {
                "uri": "https://portalxxxxxxxxxxxxxxxx.blob.core.windows.net/vhds/ABCDEdbs00063-ABCDEdbs00063-0907-1-e-drive.vhd"
              },
              "caching": "None",
              "diskSizeGB": 1023
            }
          ]
        },
        "osProfile": {
          "windowsConfiguration": {
            "provisionVMAgent": true,
            "enableAutomaticUpdates": true,
            "winRM": {
              "listeners": [
                {
                  "protocol": "Https",
                  "certificateUrl": "https://ABCDEdbs00063.vault.azure.net/secrets/93AC57E047AA1B3173B487BA337B46F1C83BE9F9/64a9474f4e764a49b909a8991f44391f"
                }
              ]
            }
          },
          "secrets": [
            {
              "sourceVault": {
                "id": "/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/resourceGroups/ABCDEdbs00063_RG/providers/Microsoft.KeyVault/vaults/ABCDEdbs00063"
              },
              "vaultCertificates": [
                {
                  "certificateUrl": "https://ABCDEdbs00063.vault.azure.net/secrets/93AC57E047AA1B3173B487BA337B46F1C83BE9F9/64a9474f4e764a49b909a8991f44391f",
                  "certificateStore": "My"
                }
              ]
            }
          ]
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id":
"/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/resourceGroups/ABCDEdbs00063_RG/providers/Microsoft.Network/networkInterfaces/ABCDEdbs00063-PrimaryNic"
            }
          ]
        },
        "provisioningState": "Succeeded"
      },
      "resources": [
        {
          "id":
"/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/resourceGroups/ABCDEDBS00063_RG/providers/Microsoft.Compute/virtualMachines/ABCDEdbs00063/extensions/VMSna
pshot"
        }
      ],
      "type": "Microsoft.Compute/virtualMachines",
      "location": "eastus",
      "id": "/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/resourceGroups/ABCDEDBS00063_RG/providers/Microsoft.Compute/virtualMachines/ABCDEdbs00063",
      "name": "ABCDEdbs00063"
    }
  ],
  "nextLink":
"https://management.azure.com:443/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/providers/Microsoft.Compute/virtualMachines?api-version=2016-03-30&$skipto
ken=3e647f01-1865-43ad-YYYY-YYYYYYYYYYYY!/Subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/ResourceGroups/ABCDEDBS00084_RG/VMs/ABCDEDBS00084"
}

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:57: d83599d0-81cc-4f62-YYYY-YYYYYYYYYYYY - AcquireTokenHandlerBase: === Token Acquisition started:
 Authority: https://login.microsoftonline.com/40ef5872-310e-441c-YYYY-YYYYYYYYYYYY/
 Resource: https://management.core.windows.net/
 ClientId: 1950a258-227b-4e31-YYYY-YYYYYYYYYYYY
 CacheType: Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache (1 items)
 Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 11/29/2016 13:38:57: d83599d0-81cc-4f62-YYYY-YYYYYYYYYYYY - TokenCache: Looking up cache for a token...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:57: d83599d0-81cc-4f62-YYYY-YYYYYYYYYYYY - TokenCache: An item matching the requested resource was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 11/29/2016 13:38:57: d83599d0-81cc-4f62-YYYY-YYYYYYYYYYYY - TokenCache: 6.72536748166667 minutes left until token in cache expires
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:57: d83599d0-81cc-4f62-YYYY-YYYYYYYYYYYY - TokenCache: A matching item (access token or refresh token or both) was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 11/29/2016 13:38:57: d83599d0-81cc-4f62-YYYY-YYYYYYYYYYYY - AcquireTokenHandlerBase: === Token Acquisition finished successfully. An access token was
retuned:
 Access Token Hash: hJtK77Kn8n2s/NLjJ6K/ZLAoe+wTbqPl+??????????=
 Refresh Token Hash: 7ghuBP5H1QhR0xD27ALA/sErMgA5cnZVj??????????=
 Expiration Time: 11/29/2016 13:45:40 +00:00
 User Hash: NIwAG0nlvx4LULaCWrL0o9jIGNCuUdGRp??????????=

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/providers/Microsoft.Compute/virtualMachines?api-version=2016-03-30&$skiptoken=3
e647f01-1865-43ad-YYYY-YYYYYYYYYYYY!/Subscriptions/9af2fe58-e215-4e90-YYYY-YYYYYYYYYYYY/ResourceGroups/ABCDEDBS00084_RG/VMs/ABCDEDBS00084

Headers:
x-ms-client-request-id        : f559fd4a-2c57-42f4-YYYY-YYYYYYYYYYYY
accept-language               : en-US

Body:


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-served-by                : 71d495ee-920b-4e8f-bd25-3df17b1f47bc_131239898916350284
x-ms-request-id               : a8210012-6be7-4441-YYYY-YYYYYYYYYYYY
Cache-Control                 : no-cache
Server                        : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 14928
x-ms-correlation-request-id   : d82906d4-4409-4f4c-YYYY-YYYYYYYYYYYY
x-ms-routing-request-id       : EASTUS2:20161129T133856Z:d82906d4-4409-4f4c-YYYY-YYYYYYYYYYYY
Date                          : Tue, 29 Nov 2016 13:38:56 GMT

Body:
{
  "value": []
}


ResourceGroupName                        Name               Location                 VmSize                 OsType                    NIC     ProvisioningState
-----------------                        ----               --------                 ------                 ------                    ---     -----------------

---8<------  50 lines of server output elided ------>8---

DEBUG: 13:38:58 - GetAzureVMCommand end processing.
DEBUG: 13:38:58 - GetAzureVMCommand end processing.

Script/Steps for Reproduction

Execute Get-AzureRmVm for a subscription that would return more than the page items (50) Passing the URI from the debug text as a -NextLink parameter also returns an empty body.

TrickyTic avatar Nov 29 '16 14:11 TrickyTic

@singhkays Can you take a look?

markcowl avatar Nov 30 '16 20:11 markcowl

This is not my experience for centralus at least, and I see it make multiple requests in debug output. For reference on PSv5/AzureRM v3.3

$vms = get-azurermvm
WARNING: Breaking change notice: In upcoming releaese, top level properties, DataDiskNames and NetworkInterfaceIDs, will be removed from VM object because they are also in Storage
Profile and NetworkProfile, respectively.

$vms.Count
421

anyasabo avatar Jan 10 '17 18:01 anyasabo

@jonsabo Thanks for sharing your experience!

@TrickyTic Can you check with the latest PS version?

singhkays avatar Jan 10 '17 19:01 singhkays

Happy to help.

I have just checked and it still fails for me.

I have 65 ARM virtual machines in EastUS, only 50 are returned by the cmdlet (stops at nextlink).

  • Updated to PS 5.0, only 50 returned
  • Updated to PS 5.1, only 50 returned
  • Updated AzureRM.Compute to 2.4.0 (AzureRM 3.3), only 50 returned
  • Tried same on a colleague's Windows 10 PS 5.1, only 50 returned
  • Tried -Status to get alternative object type, only 50 returned
  • Tried to get missing objects individually using -Name/-ResourceGroup and every one is returned OK.
  • Tried to get all VMs using Get-RmResource and all 65 are returned
PS C:\> (Get-AzureRmResource | where-object {$_.ResourceType -eq "Microsoft.Compute/virtualMachines"}).Count
65

TrickyTic avatar Jan 11 '17 10:01 TrickyTic

Closing as this no longer seems to be an issue. Please feel free to re-open this issue if you are still seeing the same problem.

cormacpayne avatar Mar 28 '18 00:03 cormacpayne