Hi everyone, in this post, I will show you how to enable blob versioning on your Azure storage account using PowerShell and Azure CLI. When blob versioning is enabled, you can restore a previous version of a blob to recover data if modified or deleted by mistake.

What Microsoft Says About Blob versioning: As part of your comprehensive data protection strategy, Microsoft recommends enabling all of the following blob data protection features:

Important: Disabling blob versioning does not delete existing blob versions. When you turn off blob versioning, any existing versions remain accessible, but no new versions are subsequently created.

Prerequisites

  • 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.
  •  The Az.Storage module version 2.3.0 or later must be installed.

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.

Enable blob versioning

To enable blob versioning, you should use the Update-AzStorageBlobServiceProperty cmdlet with the following syntax.

Update-AzStorageBlobServiceProperty

Verify the changes made

You can verify that versioning is enabled by using the Get-AzStorageBlobServiceProperty cmdlet with the following syntax.

Then, you can check that the versions are created on the write operation using the following commands. In the following example, I have a container, “folder01,” containing a blob “Text_Document.txt.”

As you can see, using the following command, you can list all the blob versions.

Get-AzStorageContainer

Disable blob versioning

To disable blob versioning, you should use the Update-AzStorageBlobServiceProperty cmdlet with the following syntax.

Azure CLI Workaround

In this case, we will use Azure Cloud Shell, a browser-based shell built into Azure Portal. This allows us to use the Azure command-line tools (Azure CLI and Azure PowerShell) directly from a browser. If you want to know more about Azure Cloud Shell, check out this link.
First, we define the characteristics of our environment and store the values in variables.

Enable blob versioning

To enable blob versioning in your storage account, you should use the following command.

Blob storage versioning

Verify the changes made

You can verify that blob versioning has been enabled by using the following command.

Then, you can check that the versions are created on the write operation using the following commands. In the next example, I have a container, “folder01,” containing a blob “Text_Document.txt.”

As you can see, using the following command, you can list all the blob versions.

Azure Blob storage versioning

Disable blob versioning

To disable blob versioning, you should use the following command.

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

If you want to know more about Azure blob versioning, check out this link.