What is the fastest way to get the LastModified Timestamp of a Recent Blob in the Azure Storage Container?

Varun 1 Reputation point
2022-09-28T19:00:39.887+00:00

I would like to know if there is a better way to get the LastModified timestamp of a the recent blob. One way to find the last recent blob in Azure Storage Container is to traverse through all the blobs and sort the results in Descending Order using the Last Modified timestamp value.

But then if the container has large set of files then this operation may take longer. Do we have any better ways to get the recent blob and its Last Modified Timestamp

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.
2,944 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,639 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SaiKishor-MSFT 17,221 Reputation points
    2022-09-28T22:12:15.347+00:00

    @Varun Thank you for reaching out to Microsoft Q&A. I understand that you want to get the Lastmodified Timestamp of a recent blob in Azure and want to know the fastest way to get it.

    You can get it as discussed in this thread- https://social.msdn.microsoft.com/Forums/en-US/90465e17-5f85-4075-92df-248b8abe7052/get-most-recent-last-modified-file-name-from-containers-subfolder?forum=windowsazuredata

    # Connect to Azure with an interactive dialog for sign-in  
    #Connect-AzAccount  
    $container_name = 'containername'  
    $connection_string = 'DefaultEndpointsProtocol=https;AccountName=AccName;AccountKey=AccKey'  
    $storage_account = New-AzStorageContext -ConnectionString $connection_string  
    # Get the blobs list and then sort them by last modified date descending  
    $blobs = Get-AzStorageBlob -Container $container_name -Context $storage_account -Blob *.bak | sort @{expression="LastModified";Descending=$true}  
    $latestBlob = $blobs[0]  
    write $latestBlob.Name  
    

    Does this help or are you looking for something more? Please let me know. Thanks!

    Remember:

    Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.

    Want a reminder to come back and check responses? Here is how to subscribe to a notification.

    2 people found this answer helpful.