Hello everyone, in this post, I want to show you the Azure PowerShell commands that I have been collecting to manage containers and blobs in the Azure Storage service.

Prerequisites

  • This tutorial assumes that you already have a Microsoft Azure account configured.
  • You created a Resource Group for these resources and the new ones deployed in this tutorial will join that group. If you want to know how to create a Resource Group, check out this link.
  • You can use an existing Storage Account, or you can create a new one. If you want to know how to create a Storage Account using PowerShell, check out this link.

Azure PowerShell Workaround

If you want to know how to install the PowerShell Azure module on your machine, check out this link.

The simplest way to get started is to sign in interactively at the command line.

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account.
If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Once you set your default subscription, you’re ready to start.

Set the variables

Here, we define the characteristics of our environment and the resource’s properties.

Create an Azure Storage container

A container organizes a set of blobs, similar to a directory in a file system. A storage account can contain an unlimited number of containers and a container can store an unlimited number of blobs.

Important: The container name must be lowercase.

To create a container with the Azure PowerShell cmdlet, use the New-AzStorageContainer cmdlet, as shown below:

New-AzStorageContainer

the -Permission parameters specify the level of public access to this container.

List Azure Storage containers

if you want to list all the containers within your storage account, use the following command:

Get-AzStorageContainer

Remove an Azure Storage container

If you made a mistake when setting the name or simply want to remove the container, use the Remove-AzStorageContainer cmdlet as shown below.

Create an Azure Storage blob

When uploading a file to the container, the storage service creates a blob, this blob can be created of three types: block blobs, append blobs, and page blobs. If nothing is specified in the -BlobType parameter, by default it will be created of the block type.

Important: Once the blob has been created, its type cannot be changed.

Uploads a local file to an Azure Storage blob.

You can use Azure PowerShell to load a file into the container, using the Set-AzStorageBlobContent cmdlet as shown below:

Set-AzStorageBlobContent

You can also upload all the files in a specific directory, using the following commands:

Set-AzStorageBlobContent

List Azure Storage blobs

If you want to list all blobs within a specific container, use the following command:

Get-AzStorageBlob

Downloads an Azure Storage blob

The Get-AzStorageBlobContent cmdlet downloads the specified storage blob to the local computer.

Get-AzStorageBlobContent

Using the following command, you can download all the contents of the container to a local directory of your computer.

Remove an Azure Storage blob

To remove a particular blob from a container, use the Remove-AzStorageBlob cmdlet as shown below.

Remove-AzStorageBlob

But if you want to remove all the contents of a container, you should use the following command.

Thanks for reading my post. I hope you find it useful.

If you want to know more about Azure Storage, check out this link: https://docs.microsoft.com/en-us/azure/storage/common/storage-introduction