Retrieving Last Modified Dates for All Tables in Azure Storage Account Using PowerShel

Niket Kumar Singh 435 Reputation points
2025-03-10T14:46:48.2633333+00:00

I am working on a project that requires obtaining the last modified dates for all tables within our Azure Storage account. The objective is to monitor and manage data effectively without making any modifications to the existing data.

What We Have Tried:

We have attempted to use Azure PowerShell cmdlets to achieve this. Our approach included:​

  1. Setting the Azure Subscription Context:
powershell
Copy
Set-AzContext -SubscriptionId "<Your Subscription ID>"
  1. Retrieving the Storage Account Key:
powershell
Copy
$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName "<Your Resource Group>" -Name "<Your Storage Account>").Value[0]
  1. Creating a Storage Context:
powershell
Copy
$storageContext = New-AzStorageContext -StorageAccountName "<Your Storage Account>" -StorageAccountKey $storageAccountKey
  1. Iterating Over Each Table to Fetch Entities and Determine the Last Modified Date:
powershell
Copy
$tables = Get-AzStorageTable -Context $storageContext
foreach ($table in $tables) {
    $entities = Get-AzTableRow -TableName $table.Name -Context $storageContext | Sort-Object Timestamp -Descending
    $latestTimestamp = $entities[0].Timestamp.DateTime.ToString("yyyy-MM-dd HH:mm:ss")
    Write-Output "Table: $($table.Name) | Last Modified: $latestTimestamp"
}

Challenges Encountered:

  • The Get-AzTable cmdlet is not recognized, indicating that the AzTable module may not be installed or imported correctly.​
  • Errors related to parameter sets not being recognized, leading to execution failures.​

Objective:

We seek guidance on:

Module Installation and Import: How can we ensure that the AzTable module is installed and imported correctly in our PowerShell environment?​

Retrieving Last Modified Dates: What is the recommended approach to retrieve the last modified dates for all tables in an Azure Storage account using PowerShell?​

Ensuring Read-Only Operations: How can we confirm that the script performs only read-only operations to prevent any unintended data modifications?​

Error Handling: What are the best practices for handling errors and exceptions in this context to ensure the script runs smoothly?​

Additional Information:

  • We have already defined the storage account name, resource group name, and subscription ID.​
  • We are operating within the Azure Cloud Shell environment, which should have the necessary modules pre-installed.​

Any insights, code snippets, or references to relevant documentation would be greatly appreciated.

Thank you for your assistance.

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,412 questions
{count} votes

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.