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.
In case you are curious, the access option controls if and how the public can access the contents of your container:
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.Related Article:
More in Microsoft Azure
Microsoft Now Lets IT Admins Review & Remove Inactive Azure AD Users
May 27, 2022 | Rabia Noureen
Build 2022: Microsoft's Intelligent Data Platform Combines Data and Analytics
May 25, 2022 | Rabia Noureen
Microsoft Revises Restrictive Cloud Licensing Policies to Avoid EU Antitrust Probe
May 19, 2022 | Rabia Noureen
Microsoft's Azure AD Conditional Access Service Can Now Require Reauthentication
May 13, 2022 | Rabia Noureen
Microsoft Addresses Cross-Tenant Database Vulnerability in Azure PostgreSQL
Apr 29, 2022 | Rabia Noureen
Microsoft Simplifies IT Monitoring with New Azure Managed Grafana Service
Apr 19, 2022 | Rabia Noureen
Most popular on petri