0

I am doing a batch insert with powershell to Azure table. using latest Az modules, not AzureRm.

$context = New-AzStorageContext $storageAccountName -StorageAccountKey $storageAccountKey
$table = (Get-AzStorageTable –Name myTable –Context $context)

foreach($item in $items){
    [Microsoft.WindowsAzure.Storage.Table.TableBatchOperation]$batchOperation = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.TableBatchOperation
    $entity = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity -ArgumentList $partitionKey, $rowKey
    $entity.Properties.Add("ID", $id)
    $batchOperation.InsertOrReplace($entity)
}
if ($batchOperation.Count -ne 0) {
    $table.CloudTable.ExecuteBatch($batchOperation)
}

But am getting error as:

Cannot find an overload for "ExecuteBatch" and the argument count: "1"

"ExecuteBatch" is this method only available in the old AzureRm module?

0

1 Answer 1

2

ExecuteBatch operation is definitely available.

enter image description here

I believe you're getting this error is because you're using incorrect namespace. You should be using Microsoft.Azure.Cosmos.Table instead of Microsoft.WindowsAzure.Storage.Table.

Please try the following code. I tried it and it works:

$storageAccountName = "account-name";
$storageAccountKey = "account-key=="

$context = New-AzStorageContext $storageAccountName -StorageAccountKey $storageAccountKey
$table = (Get-AzStorageTable –Name myTable –Context $context)

foreach($item in $items){
    [Microsoft.Azure.Cosmos.Table.TableBatchOperation]$batchOperation = New-Object -TypeName Microsoft.Azure.Cosmos.Table.TableBatchOperation
    $entity = New-Object -TypeName Microsoft.Azure.Cosmos.Table.DynamicTableEntity -ArgumentList $partitionKey, $rowKey
    $entity.Properties.Add("ID", $id)
    $batchOperation.InsertOrReplace($entity)
}
if ($batchOperation.Count -ne 0) {
    $table.CloudTable.ExecuteBatch($batchOperation)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.