Jdreamer
Jdreamer

Reputation: 61

Azure Table Storage: a script to populate new column for existing tables

I have some tables in my Azure Table Storage and need to deploy a script to populate a new column with empty data for all of them.

I know that some management could be done via PowerShell, but I was unable to find any relevant example or documentation on how to perform this task.

Any help would be appreciated.

Upvotes: 1

Views: 2528

Answers (2)

Jim Xu
Jim Xu

Reputation: 23111

Regarding the PowerShell script, please refer to the following code:

Install-Module -Name AzTable

$groupName=""
$StorageAccountName = ""
$StorageAccountKey = ""
$vaule=" "
$context = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$tables = Get-AzStorageTable -Context $context
Foreach($table in $tables){
    $table = Get-AzTableTable -storageAccountName $StorageAccountName -resourceGroup $groupName="" -TableName
    $entities=Get-AzTableRow -Table $table
    ForEach($e in $entities){
        $entity = New-Object Microsoft.Azure.Cosmos.Table.DynamicTableEntity($e.PartitionKey,$e.RowKey)
        $entity.Properties.Add("Name", $vaue)
        $table.Execute([Microsoft.Azure.Cosmos.Table.TableOperation]::InsertOrMerge($entity))
        Get-AzTableRow -Table $table -PartitionKey $e.PartitionKey -RowKey $e.RowKey
    }

}

Upvotes: 2

Gaurav Mantri
Gaurav Mantri

Reputation: 136136

I have some tables in my Azure Table Storage and need to deploy a script to populate a new column with empty data for all of them.

Basically Azure Table is a key/value pair store so it can't really have columns (key) with no data (value) in it. This is applicable to all supported data types with an exception of String data type where you can store an empty string (it's still not null) as value for a key.

As to how you go about doing it, here're the steps you can follow:

  1. Fetch the entities for which you wish to add a key. To reduce the response payload, you can simply fetch the PartitionKey and RowKey attributes.
  2. For each entity you receive, simply add a new attribute. Please ensure that the attribute's data type is String and set the value of that attribute to empty string ("").
  3. Last you would want to call Merge Entity operation on those entities. This will ensure that only the new attribute will get added. All other existing attributes in that entity will remain unchanged.

Unfortunately I am not too familiar with PowerShell to provide exact syntax. But this should give you enough idea to get going.

Upvotes: 1

Related Questions