Skip to navigation Skip to content
GeralexGR

Personal blog

  • Home
  • About
  • Contact
  • Home
  • About
  • Contact
  • Test
Posted on May 4, 2022May 4, 2022 by geralexgr — Leave a comment

Download latest file from blob storage through az cli

Given that you have a blob storage container with multiple files, you could download the most latest one easily with az cli

In my scenario I have a container named backups which includes multiple MS SQL backups. I wanted to download the latest in order to restore through a pipeline on SQL server.

In order to accomplish that you should first login with az cli.

az login

If this is not possible through automation you would have to create a managed identity for your resource. The code is uploaded on the below gist.

$container_name_input = "backups"
$sg_con_string = "XXX"
$json = az storage blob list –container-name $container_name_input –connection-string $sg_con_string | ConvertFrom-Json | Sort-Object -Descending { $_.properties.CreationTime } | Select-Object name
az storage blob download –file $json[0].name –name $json[0].name –container-name $container_name_input –connection-string $sg_con_string
view raw download-latest-blob-storage-account-az-cli hosted with ❤ by GitHub

You should replace your connection string by getting yours under access keys.

If you remove descending date the default value would be Ascending.

By executing the script you will get a json output like the below:

Share article

  • Share
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to email a link to a friend (Opens in new window) Email

Related

Categories: Azure, Cloud, Scripts
Tags: account az cli download, az, az cli, blob, blob container download, cli, download, sg account download blob, storage, storage account, storage-account

Post navigation

Previous post: Powershell -Contains does not evaluate string with Get-Content
Next post: Authenticate to Azure management API using az cli

Leave a ReplyCancel reply

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

Mastering Azure Devops CI/CD Pipelines with YAML
Learn how to create advanced automation scenarios using YAML and Azure Devops: https://www.udemy.com/course/mastering-azure-devops-cicd-pipelines-with-yaml
Social
Subscribe on my YouTube channel for more tutorials:


Follow me on Linkedin: Linkedin profile
Azure DevOps platform Fundamentals – Build CI/CD pipelines
Start your journey with Azure DevOps platform: https://www.udemy.com/course/azure-devops-platform-fundamentals-build-cicd-pipelines/
Adblock notice
Support this blog to maintain its operational costs by turning off Adblock or donate a small amount using the button below
Blog Stats
  • 371,262 Views

Join 10 other subscribers
Recent Posts
  • Chaos Engineering in Azure: Automating Resilience Testing with Terraform & Pipelines
  • Azure Chaos Studio terraform properties
  • Automating chaos experiment execution with Azure DevOps
  • Chaos Engineering with Azure – simulate web app failure
  • Azure AI Studio – Deploy and use your first model
Top Posts
  • Pass variables values inside terraform modules
  • Log commands for all users on Linux - Redhat auditd
  • Trigger Azure Devops build pipelines using REST API
  • Authentication failed. The 'Authorization' header is missing - Invoke-WebRequest Azure ARM
  • Powershell handle Invoke-WebRequest 404 error
  • Pass secrets as ENV variables on docker build - Azure devops
  • Connect to Azure resources with Managed Identity – Storage account example
  • Allow non Admin users to connect through RDP on domain controller
  • The specified module 'MSAL.PS' was not loaded because no valid module file was found in any module directory.
  • Pass parameters from Power automate to Azure DevOps pipeline using rest api
Categories
  • AI
  • Ansible
  • Automation
  • AWS
  • Azure
  • BotFramework
  • C# & .NET
  • Chaos Engineering
  • Cloud
  • Devops
  • Docker
  • Github
  • Infrastructure
  • Kubernetes
  • Linux
  • Monitoring
  • Scripts
  • Security
  • Terraform
  • Testing
  • UWP apps – Windows 10
  • VMware
  • Web Development
  • Windows
  • Xamarin
Tags
.net ansible api appservice az cli Azure azuredevops azure devops build c# centos cli command container containers deploy devops docker github html identity jobs k8s kubernetes linux managed identity modules pipeline pipelines powershell redhat release rest api security storage account teamcity terraform update variables visual studio vmware web web app windows xamarin.forms
Archives
  • February 2025
  • November 2024
  • October 2024
  • August 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • December 2019
  • August 2019
  • April 2019
  • March 2019
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • March 2018
  • July 2017
  • May 2017
  • February 2016
  • October 2015
  • August 2015
  • February 2015
  • November 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
© GeralexGR 2025
Built with Storefront.