Learn how to copy files to Azure blob storage with the PowerShell Set-AzureStorageBlobContent
cmdlet in this handy tutorial.
I’ve been doing a lot of Azure IaaS work via ARM lately in PowerShell. As a result, I’ve unfortunately found out how bad the documentation and behavior is for the Azure PowerShell module but I’ve persisted and have overcome!
As part of this project, I’ve had to upload a bunch of files up to an Azure storage account container. Being used to PowerShell’s Copy-Item
cmdlet to copy files I figured there had to be something like that for Azure in the Azure PowerShell module but I was let down. Instead, I was faced with using three separate cmdlets just to get a single file up to a common storage container.
Once I figured out how to do it, I didn’t really feel like remembering how to get a file up to an Azure storage container every time. So, just as any PowerShell developer would do, I made an easy-to-use function called Copy-AzureItem
to copy files to Azure Blob Storage. This function has saved me tons of time and hopefully it can do the same for you as well.
Here’s how it works:
First, in order to get a file into an Azure ARM storage container entails three different “objects”; a storage account, a storage account container and the blob or file itself. You must specify each of these “objects” when uploading the file. To do this, you can use three different cmdlets on one line.
As you can tell, I’m using splatting to provide the various parameters to each cmdlet.
All of this just to copy a file up to Azure? No thanks! Instead, how about doing something like this?
Much easier! Granted, I’m defaulting the resource group and storage account in the function but that’s easy to update.
So, without further ado, feel free to download this function from my Github repo. If you’re too lazy to do that, copy and paste it from here.
Source:
https://adamtheautomator.com/copy-files-to-azure-blob-storage/