May 06 2022
Data Center

How to Copy Files to a Microsoft Azure Storage Account Using PowerShell

Follow these four steps for a quick, automated way to get data onto Microsoft’s cloud.

Storage is a finite IT asset, and organizations can’t get enough of it. Businesses are consuming more storage every day, and it’s up to IT to keep up. Rather than consistently add expensive new on-premises data center storage, many choose the cloud; Microsoft’s Azure is a popular choice.

If a business needs to get data to an Azure storage account quickly via automation, PowerShell is a great choice. Using PowerShell, businesses can create scripts to perform migrations, upload new data and manage Azure storage, all from the command line. Here are four steps to get started copying files to Azure storage with PowerShell.

1. Download the Azure PowerShell Module

Microsoft provides a PowerShell module to manage Azure storage, but it doesn’t come installed by default on your Linux or Windows system. You’ll first need to download and install the Azure Az PowerShell module from the PowerShell Gallery using the Install-Module cmdlet. This contacts Microsoft’s PowerShell Gallery, and downloads and installs the appropriate Az module onto your system.

Click the banner below to unlock exclusive cloud content when you become an Insider.

2. Connect to Azure

Once you have the Azure PowerShell module downloaded, you must authenticate to your Azure subscription. Microsoft needs to know what storage accounts you have access to and what kind of permissions you have in storage accounts under your Azure subscription.

The Connect-AzAccount cmdlet displays a web page that allows you to provide your Microsoft account’s username and password. (If you have multiple Azure subscriptions, don’t forget the SubscriptionName parameter.)

3. Create a Storage Container

Your local file system uses directories or folders to separate files. In Azure, these groups of files are known as containers. Every file in an Azure storage account must be inside a container. You can create a container using the New-AzStorageContainer cmdlet.

To quickly create the required container, use the Get-AzStorageAccount cmdlet to pass the appropriate storage account to the New-AzStorageContainer cmdlet will quickly create the required container:

Get-AzStorageAccount -Name <storage_account> -ResourceGroupName <resource_group> |
New-AzStorageContainer -Name <container_name>

4. Upload Files to Azure Storage

Once you have a storage container to upload your files into, you can upload one or more files using the Set-AzStorageBlobContent cmdlet. This cmdlet needs to know the storage account and container to upload files to. One way to provide this information is by piping the necessary objects using the Get-AzStorageAccount and Get-AzStorageContainer cmdlets below:

Get-AzStorageAccount -Name <storage_account> -ResourceGroupName <resource_group> |
Get-AzStorageContainer -Name <container_name> |
Set-AzStorageBlobContent -File <file_path> -Blob '<file_name>'

Don’t forget to run Disconnect-AzAccount when you’re done if you’d prefer to not save your Azure credentials on the machine.

The cloud offers small businesses a way to catch up to enterprises when it comes to harnessing data. Find out how at

CACTUS Creative Studio/Stocksy

Become an Insider

Unlock white papers, personalized recommendations and other premium content for an in-depth look at evolving IT