Azure Storage Filter Last Modified Date

This blog article shows you how to filter the files from Azure Storage by Last Modified date. The snippet of the PowerShell as follows.

Connect-AzAccount -Tenant TenantId -Subscription SubscriptionId

$resourceGroupName =” resourceGroupName “

$storageAccName =” storageAccName “

$directoryPath =”document”

$container = “container”

$ctx=(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context

Get-AzStorageBlob -Container “document” -Context $ctx | Where-Object {$_.LastModified -gt “2024-03-15”}

Certainly! Let’s break down the PowerShell script step by step:

1. Connect-AzAccount -Tenant TenantId -Subscription SubscriptionId:

    • This command connects to your Azure account using the specified tenant ID and subscription ID.
    • It authenticates you to perform operations against your Azure resources.

2. Variable Assignments:

    • $resourceGroupName: This variable holds the name of the Azure resource group where your storage account resides.
    • $storageAccName: This variable stores the name of your Azure storage account.
    • $directoryPath: Specifies the directory path within the storage account container.
    • $container: The name of the storage container you want to work with.

3. $ctx=(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context:

    • This line retrieves the storage account context (connection information) for the specified resource group and storage account.
    • The context is necessary for subsequent operations on the storage account.

4. Get-AzStorageBlob -Container "document" -Context $ctx | Where-Object {$_.LastModified -gt "2024-03-15"}:

    • This command retrieves a list of blobs (files) from the specified container named “document” within the storage account.
    • The -Context $ctx parameter ensures that the command uses the previously obtained storage account context.
    • The Where-Object filter is applied to select only blobs where the LastModified timestamp is greater than March 15, 2024.

In summary, this script connects to your Azure account, retrieves the storage account context, and then lists the blobs in the “document” container that were modified after March 15, 2024. If any blobs meet the criteria, they will be displayed in the output12

Also: Start and Stop Azure App Service using PowerShell

powershell1

You can see the return result sample as above.

Source code download: https://github.com/chanmmn/powershell/tree/main/2024/AzureStorageFilterDate?WT.mc_id=DP-MVP-36769

Reference: https://stackoverflow.com/questions/66763313/powershell-azure-storage-accounts-get-last-authentication-time-date/?WT.mc_id=DP-MVP-36769

About chanmingman

Since March 2011 Microsoft Live Spaces migrated to Wordpress (http://www.pcworld.com/article/206455/Microsoft_Live_Spaces_Moves_to_WordPress_An_FAQ.html) till now, I have is over 1 million viewers. This blog is about more than 50% telling you how to resolve error messages, especial for Microsoft products. The blog also has a lot of guidance teaching you how to get stated certain Microsoft technologies. The blog also uses as a help to keep my memory. The blog is never meant to give people consulting services or silver bullet solutions. It is a contribution to the community. Thanks for your support over the years. Ming Man is Microsoft MVP since year 2006. He is a software development manager for a multinational company. With 25 years of experience in the IT field, he has developed system using Clipper, COBOL, VB5, VB6, VB.NET, Java and C #. He has been using Visual Studio (.NET) since the Beta back in year 2000. He and the team have developed many projects using .NET platform such as SCM, and HR based applications. He is familiar with the N-Tier design of business application and is also an expert with database experience in MS SQL, Oracle and AS 400.
This entry was posted in .Net, Cloud, Community, Computers and Internet, programming and tagged . Bookmark the permalink.

1 Response to Azure Storage Filter Last Modified Date

  1. Pingback: Azure Storage download files using PowerShell | Chanmingman's Blog

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.