DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Hands-On with Azure Local via the Azure Portal
  • Effective Secrets Management: Retrieving Secrets From Azure Key Vault With Powershell Script
  • Power of Azure B Series Virtual Machines
  • Azure Virtual Machines

Trending

  • The Agentic Agile Office: Streamlining Enterprise Agile With Autonomous AI Agents
  • Using LLMs to Automate Data Cleaning and Transformation Pipelines
  • Run Gemma 4 on Your Laptop: A Hands-On Guide to Google's Latest Open Multimodal LLM
  • Offline-First Patch Management for 10,000 Edge Nodes: A Practical Architecture That Scales
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Download Blob to Azure VM Using Custom Script Extension via PowerShell

Download Blob to Azure VM Using Custom Script Extension via PowerShell

By 
Mourya Chigurupati user avatar
Mourya Chigurupati
·
May. 07, 20 · Code Snippet
Likes (1)
Comment
Save
Tweet
Share
9.1K Views

Join the DZone community and get the full member experience.

Join For Free

Virtual Machines in Azure can be spun up in multiple ways — Azure Portal, PowerShell, or by deploying ARM templates. They are created to serve a purpose, and often, we come across the need to store files in the VM. This can be achieved in multiple ways — Disks, AzCopy, download from Blob, Github, or other URLs. Installing or copying these files post-VM-creation is a daunting task, as that requires you to RDP or SSH into the machine and then start executing commands.

With the help of Custom Script Extension, copying files post VM creation can be automated with a simple PowerShell script. All you have to do is point out the location to the PowerShell script stored as a Blob in one of the containers.

In this post, I would like to share the simple PowerShell script that can be used as a Custom Script Extension.


Shell
 




xxxxxxxxxx
1
22


 
1
# Install the packages required
2
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
3
Install-Module Az.Storage -Force
4

          
5
# Storage account name and Container name
6
$StorageAccountName = "Your-Storage-Account-Name"
7
$ContainerName = "Your-Storage-Account-Container-Name"
8

          
9
# Give the connection string.
10
$ConnectionString = "DefaultEndpointsProtocol=https;AccountName=Your-Storage-Account-Name;AccountKey=Your-Storage-Account-Key"
11
$Ctx = New-AzStorageContext -ConnectionString $ConnectionString
12

          
13
#Download File
14
$FileName1 = "ABC.txt"
15
$FileName2 = "XYZ.txt"
16

          
17
#Destination Path
18
$localTargetDirectory = "C:\"
19

          
20
#Download Blob to the Destination Path
21
Get-AzStorageBlobContent -Blob $FileName1 -Container $ContainerName -Destination $localTargetDirectory -Context $ctx
22
Get-AzStorageBlobContent -Blob $FileName2 -Container $ContainerName -Destination $localTargetDirectory -Context $ctx


Open file in GitHub.

For more Azure snippets, follow this GitHub Repo — Azure-Snippets

Virtual Machine PowerShell azure Download

Opinions expressed by DZone contributors are their own.

Related

  • Hands-On with Azure Local via the Azure Portal
  • Effective Secrets Management: Retrieving Secrets From Azure Key Vault With Powershell Script
  • Power of Azure B Series Virtual Machines
  • Azure Virtual Machines

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook