使用 Power Shell 批量插入 Azure Table 存储

Batch insert into Azure Table Storage using Power Shell

是否有类似于 AzureTable实体模块的东西可用于在 Azure Table 存储中插入批量数据。

以下代码将帮助您执行批量插入操作

Connect-AzAccount

$ResourceGroupName = "testfun06"
$StorageAccountName="testfun06bf01"
$TableName="People"

$keys=Get-AzStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName

$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName  -StorageAccountKey $keys[0].Value
$table = Get-AzStorageTable  -Name $TableName -Context $ctx

$e = New-Object Microsoft.Azure.Cosmos.Table.DynamicTableEntity("Jim","test")
$e1 = New-Object Microsoft.Azure.Cosmos.Table.DynamicTableEntity("Jim","test1")
[Microsoft.Azure.Cosmos.Table.TableBatchOperation] $batchOperation = New-Object -TypeName Microsoft.Azure.Cosmos.Table.TableBatchOperation
$batchOperation.InsertOrMerge($e)
$batchOperation.InsertOrMerge($e1)

$table.CloudTable.ExecuteBatch($batchOperation)

有关更多信息,请查看 SO1 and 线程。