Reputation: 827
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?
Upvotes: 0
Views: 458
Reputation: 136306
ExecuteBatch
operation is definitely available.
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)
}
Upvotes: 2