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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Effective Secrets Management: Retrieving Secrets From Azure Key Vault With Powershell Script
  • Power of Azure B Series Virtual Machines
  • Azure Virtual Machines
  • Keep Your Application Secrets Secret

Trending

  • GitHub Copilot's New AI Coding Agent Saves Developers Time – And Requires Their Oversight
  • Orchestrating Microservices with Dapr: A Unified Approach
  • How Kubernetes Cluster Sizing Affects Performance and Cost Efficiency in Cloud Deployments
  • How to Merge HTML Documents in Java
  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
8.9K 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

  • Effective Secrets Management: Retrieving Secrets From Azure Key Vault With Powershell Script
  • Power of Azure B Series Virtual Machines
  • Azure Virtual Machines
  • Keep Your Application Secrets Secret

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!