我正在通过 Powershell 脚本从 csv 文件批量上传到 Azure 表存储,我有一个命令:$table.CloudTable.ExecuteBatch($batchOperation),我收到了我的问题标题中提到的错误邮政。我相信“ExecuteBatch”是旧 AzureRm 模块中的一种方法,而不是我正在使用的较新的 Az 模块,这导致它中断。Az 模块中是否有“ExecuteBatch”的相应方法?
1 回答
0
根据我的测试,如果我们使用新的 Azure PowerShell 模块 Az 来管理 Azure Table 存储,我们需要使用 SDK Microsoft.Azure.Cosmos.Table
。
所以如果你想使用ExecuteBatch
方法,我们需要使用命令[Microsoft.Azure.Cosmos.Table.TableBatchOperation] $batchOperation = New-Object -TypeName Microsoft.Azure.Cosmos.Table.TableBatchOperation
来创建TableBatchOperation。例如:
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)
于 2019-09-16T02:35:58.897 回答