How to enable soft delete for Azure Storage blobs using Azure CLI in Powershell?

PowerShellSoftware TestingMicrosoft Technologies

From the Azure portal, we need to access the Data Protection property of the Azure Storage account.

To enable soft delete using Az CLI, you first need to install the storage-preview extension with the below command.

az extension add -n storage-preview

Once the extension is installed, you need to make sure that you are connected to the Azure Account (if not then use “az login”) command and the proper azure subscription (using “az account set”).

To enable soft delete with Azure CLI use the below command.

az storage fs service-properties update

We can use this command with Key, connection string, or SAS token. Here, we will use the connection string. To retrieve the connection string, use the below command.

$rg = 'az204'
$strgaccount = 'az204storage05june'
$connectionstring = az storage account show-connection-string -g $rg -
n $strgaccount -otsv

To enable the soft delete with 10 days of the retention period, use the below command.

az storage fs service-properties update `
   --delete-retention `
   --delete-retention-period 10 `
   --account-name $strgaccount `
   --connection-string $connectionstring



You can also use the storage account key instead of the connection string as shown below.

az storage fs service-properties update `
   --delete-retention `
   --delete-retention-period 10 `
   --account-name $strgaccount `
   --account-key $storageaccountkey
raja
Published on 01-Sep-2021 07:57:38
Advertisements