Retrieving Last Modified Dates for All Tables in Azure Storage Account
You can use the below PowerShell code that retrieves the Azure table storage entities with last modified table.
Make sure you have assigned the Storage Table Data Contributor role to your user for the storage account.
Script:
Connect-Azaccount -Subscription "xxx"
$resourceGroup = "xxxx"
$storageAccount = "xxxxx"
try {
# Get the storage account key
$storageKey = (Get-AzStorageAccountKey -ResourceGroupName $resourceGroup -Name $storageAccount -ErrorAction Stop).Value[0]
# Create a storage context
$storageContext = New-AzStorageContext -StorageAccountName $storageAccount -StorageAccountKey $storageKey -ErrorAction Stop
# Get all table names in the storage account
$tables = Get-AzStorageTable -Context $storageContext
# Iterate through each table and fetch rows
foreach ($table in $tables) {
$tableName = $table.CloudTable.Name
$CloudTable = $table.CloudTable
Write-Host "Fetching rows from table: $tableName"
# Get all rows from the table and sort by Timestamp in descending order
$entities = Get-AzTableRow -Table $CloudTable |
Select-Object @{Name="TableName"; Expression={$tableName}}, PartitionKey, RowKey, TableTimestamp, Property1, Property2, ETag |
Sort-Object TableTimestamp -Descending
# Output results
if ($entities) {
$entities | Format-Table -AutoSize
} else {
Write-Host "No data found in table: $tableName"
}
}
}
catch {
Write-Error "An error occurred: $_"
}
Output:
Fetching rows from table: demo
TableName PartitionKey RowKey TableTimestamp Property1 Property2 Etag
--------- ------------ ------ -------------- --------- --------- ----
demo test venkat 12-03-2025 19:45:04 +05:30 W/"datetime'2025-03-12T14%3A15%3A04.5351661Z'"
Fetching rows from table: table1
TableName PartitionKey RowKey TableTimestamp Property1 Property2 Etag
--------- ------------ ------ -------------- --------- --------- ----
table1 name venkat890 12-03-2025 19:18:51 +05:30 W/"datetime'2025-03-12T13%3A48%3A51.2879744Z'"
table1 name venkat 17-10-2024 12:03:37 +05:30 test sample W/"datetime'2024-10-17T06%3A33%3A37.2273905Z'"
table1 name venkatesan 19-08-2024 11:07:21 +05:30 test key W/"datetime'2024-08-19T05%3A37%3A21.1385156Z'"
The above script:
- Fetches all tables in the storage account.
- Iterates through each table.
- Retrieves all rows from each table and sorts them by
TableTimestamp
in descending order. - Displays the results in a table format.
REST API (Shared Key Authentication):
You have used account key directly in authorization that could cause the error here.
You can use the below script which could be useful to fetch the table entities using REST API.
Script:
$storageAccountName = "xxxx"
$storageKey = "xxxxx"
# Table name
$tableName = "xxxx"
# Construct the request URL
$url = "https://$storageAccountName.table.core.windows.net/$tableName()"
# Headers
$version = "2021-02-12"
$date = (Get-Date).ToUniversalTime().ToString("R") # RFC1123 format
# Canonicalized resources and headers
$canonicalizedResources = "/$storageAccountName/$tableName()"
$canonicalizedHeaders = "x-ms-date:$date"
# String to sign
$stringToSign = "$date`n$canonicalizedResources"
# Compute the HMAC-SHA256 signature
$keyBytes = [Convert]::FromBase64String($storageKey)
$stringToSignBytes = [Text.Encoding]::UTF8.GetBytes($stringToSign)
$hmacsha256 = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha256.Key = $keyBytes
$signatureBytes = $hmacsha256.ComputeHash($stringToSignBytes)
$signature = [Convert]::ToBase64String($signatureBytes)
# Authorization header
$authHeader = "SharedKeyLite $storageAccountName`:$signature"
# Make the request
$headers = @{
"x-ms-date" = $date
"x-ms-version" = $version
"Authorization" = $authHeader
"Accept" = "application/json;odata=nometadata"
}
$response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
$response | ConvertTo-Json -Depth 10 # Pretty-print the response
Output:
{
"value": [
{
"PartitionKey": "name",
"RowKey": "venkat",
"Timestamp": "2024-10-17T06:33:37.2273905Z",
"Property1": "test",
"Property2": "sample"
},
{
"PartitionKey": "name",
"RowKey": "venkat890",
"Timestamp": "2025-03-12T13:48:51.2879744Z"
},
{
"PartitionKey": "name",
"RowKey": "venkatesan",
"Timestamp": "2024-08-19T05:37:21.1385156Z",
"Property1": "test",
"Property2": "key"
}
]
}
Reference:
- Authorize with Shared Key (REST API) - Azure Storage | Microsoft Learn
- Perform Azure Table storage operations with PowerShell | Microsoft Learn
Hope the above answer helps! Please let us know do you have any further queries.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.