Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET! Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET!
Microsoft Azure

How To Upload Files to Microsoft Azure

In this post I will show you how to upload files to an Azure storage account. This can be useful if you want to perform an offline upload of virtual hard disks, tools, or scripts.

Prepare the Storage Account

A file must be uploaded into a container in a storage account. Containers are like folders; a logical mechanism for organizing files in Azure. In my example, I want to upload a PowerShell script to Azure, so I will create a container called scripts. You can do this in two ways, the GUI or PowerShell.

In the management portal, browse into your storage account, click Containers, and click Add. Name the container, set the access level and close the wizard. Note that the name must be in lowercase.

Create a new Azure storage account container (Image credit: Aidan Finn)
Create a new Azure storage account container (Image Credit: Aidan Finn)

In case you are curious, the access option controls if and how the public can access the contents of your container:

Sponsored Content

Read the Best Personal and Business Tech without Ads

Staying updated on what is happening in the technology sector is important to your career and your personal life but ads can make reading news, distracting. With Thurrott Premium, you can enjoy the best coverage in tech without the annoying ads.

Control access to an Azure storage account container (Image Credit: Aidan Finn)
Control access to an Azure storage account container (Image Credit: Aidan Finn)

Alternatively, you can create a new container using PowerShell. Note that before we go anywhere, we must set a default storage account for use with PowerShell. This is a little annoying; you cannot specify a storage account in each storage cmdlet. Instead you have to change the default storage account each time.

The syntax for setting a default storage account is:

Set-AzureSubscription –SubscrptionName <name of your Azure subscription> -CurrentStorageAccountName <name of the storage account>

In my example, I am working with a storage account called petridemo in a subscription called Azure in Open:
Set-AzureSubscription –SubscrptionName “Azure in Open” -CurrentStorageAccountName petridemo

Now I can use New-AzureStorageContainer to create the new container to store my future upload:
New-AzureStorageContainer –Name scripts

Upload the File

Microsoft offers you PowerShell as the solution for uploading files to an Azure storage account. There are some third-party solutions that offer a UI, but for the purposes of this article, we’ll stick with Microsoft’s method, which is based on a cmdlet called Set-AzureStorageBlobContent:

Set-AzureStorageBlobContent –Container <name of destination container in Azure> -File <path and name of file to upload> -Blob <what the file name will be in Azure>

In my example, I am going to upload C:\Temp\ServerCore.ps1 to my new scripts container in the petridemo storage account.

I have already set my default storage account using Set-AzureSubscription. Now I can run Set-AzureStorageBlobContent:

Set-AzureStorageBlobContent –Container scripts -File C:\Temp\ServerCore.ps1 -Blob ServerCore.ps1

A progress bar appears in the PowerShell console to indicate upload progress. One the job is done, you can browse into your storage account container to verify that the upload is completed.

Verifying that the file was uploaded to the Azure Storage Account [Image Credit: Aidan Finn]
Verifying that the file was uploaded to the Azure Storage Account [Image Credit: Aidan Finn]
 

Related Topics:

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register
Comments (0)

Leave a Reply

Aidan Finn, Microsoft Most Valuable Professional (MVP), has been working in IT since 1996. He has worked as a consultant and administrator for the likes of Innofactor Norway, Amdahl DMR, Fujitsu, Barclays and Hypo Real Estate Bank International where he dealt with large and complex IT infrastructures and MicroWarehouse Ltd. where he worked with Microsoft partners in the small/medium business space.

Register for Advanced Microsoft 365 Day!

GET-IT: Advanced Microsoft 365 1-Day Virtual Conference - Live August 24th!

Join us on Tuesday, August 24th and hear from Microsoft MVPs and industry experts about how to take advantage of Microsoft 365 at a technical level and dive deep into the features and functionality that will make your environment more secure and compliant.

RSVP Now

Sponsored By