We can manage storage account through Azure Portal or PowerShell Scripts.
This article will explain you the commands that you need to use inside Azure CLI to manage storage account.
Download the Azure CLI in following link and choose respective installer package.
Install it on your machine. if you are working with Azure and if you had installed different tools to interact with Azure, you may have different command line tools in your machine. To find the recently installed one, just search for “Microsoft Azure Command Prompt”.
You will see a tool like below,
#First login into Azure using below command
You need to open the following link in your browser, https://aka.ms/devicelogin and provide the given code to authenticate.
If you have multiple subscription, then you can able to choose the default one.
#List out all the subscriptions
azure account list
#To set the default subscription
azure account set “name of your subscription”
#Create a storage account on the selected subscription
azure storage account create <storage account name>
Above script will ask you to provide two values, “Account Type” & “Location”. Just provide the numbers of the respective information.
To create a containers or all other storage services, we need to fix the created storage account details in environment variable so that when we run a further commands, it will consider the correct storage account. If you missed to set up environment variable then you will end up with following error.
Azure has command called “export” which is used to hold your storage connection string, just like a variable but it is not working as expected. If you try like below,
You will get below error. So we can follow different approach to have environment variable.
‘export’ is not recognized as an internal or external command,
operable program or batch file.
#Get the connection string of storage account
azure storage account connectionstring show <storage account name>
#Set Azure Connection string as environment Variable
SET AZURE_STORAGE_CONNECTION_STRING=<connection string>
#Create a container
azure storage container create <container name>
#Upload the blobs
azure storage blob upload <Path> <container name> <blob name>
azure storage blob upload E:\Encryption.png logs myblob
#Download the blobs
azure storage blob download <container name> <blob name> <local path>
azure storage blob download logs myblob E:\log.png
azure storage blob delete <container name> <blob name>
azure storage blob delete logs myblog