Home > Enterprise >  How do I get continuation token when querying Azure Table Storage via REST API on PowerShell?
How do I get continuation token when querying Azure Table Storage via REST API on PowerShell?

Time:11-11

I am using PWSH 7 / REST API to query a table with more than 1000 entries, and I can query it fine using this code:

$RGName = "MyResourceGroup"
$StorageAccount = "MyStorageAccount"
$TableName = "MyTable"
$SA = Get-AzStorageAccount -Name $StorageAccount -ResourceGroupName $RGName -verbose
$Accesskey = ($SA | Get-AzStorageAccountKey).value[0]

$Version = "2021-08-06"
$Table_url = "https://$StorageAccount.table.core.windows.net/$TableName"
$GMTTime = (Get-Date).ToUniversalTime().toString('R')
$stringToSign = "$GMTTime`n/$StorageAccount/$TableName"
$HMACSHA = New-Object System.Security.Cryptography.HMACSHA256
$HMACSHA.key = [Convert]::FromBase64String($Accesskey)
$Signature = $HMACSHA.ComputeHash([Text.Encoding]::UTF8.GetBytes($stringToSign))
$Signature = [Convert]::ToBase64String($Signature)
$Headers = @{
    'x-ms-date'    = $GMTTime
    Authorization  = "SharedKeyLite "   $StorageAccount   ":"   $Signature
    "x-ms-version" = $Version
    Accept         = "application/json;odata=fullmetadata"
}
$Item = Invoke-RestMethod -Method GET -Uri $Table_url -Headers $Headers -ContentType application/json

However, I don't get a continuation token returned, so I don't see a way to get the next entries in the table. According to this documentation, it looks like I should be getting one.

Can anyone tell me what I'm doing wrong?

CodePudding user response:

If you look at the documentation, the continuation tokens (x-ms-continuation-NextPartitionKey and x-ms-continuation-NextRowKey) are returned in response headers.

To get response headers in Invoke-RestMethod Cmdlet, you would need to specify -ResponseHeadersVariable variable and then you should be able to get those response headers.

  • Related