0
votes

I'm creating several storage accounts programmatically via StorageManagementClient and would like to enable blob versioning on account level at the time of account creation. How is this accomplished?

var storageManagementClient = new StorageManagementClient(azureCredentials)
{
     SubscriptionId = subscriptionId
};
var storageAccountCreateParameters = new StorageAccountCreateParameters
{
     // set properties
};

await storageManagementClient.StorageAccounts.CreateAsync(resourceGroupName, accountName, storageAccountCreateParameters);

I thought that this would be available as a create parameter in StorageAccountCreateParameters, but I don't see anything there.

Also see https://docs.microsoft.com/en-us/azure/storage/blobs/versioning-enable?tabs=portal

1

1 Answers

1
votes

The blob versioning is not included in the StorageAccountCreateParameters. It belongs to BlobServiceProperties class.

So after you create the storage account with your code above, you can use the following code to set blob versioning:

var p1 = new BlobServiceProperties()
{
    IsVersioningEnabled = true             
};

storageManagementClient.BlobServices.SetServiceProperties("resource_group", "account_name", p1);