【问题标题】:Cannot find overload for ExecuteBatch error in powershell在 powershell 中找不到 ExecuteBatch 错误的重载
【发布时间】:2019-09-13 16:29:13
【问题描述】:

我正在通过 Powershell 脚本从 csv 文件批量上传到 Azure 表存储,并且我有一个命令:$table.CloudTable.ExecuteBatch($batchOperation) 为此,我收到了帖子问题标题中提到的错误。我相信“ExecuteBatch”是旧 AzureRm 模块中的一种方法,而不是我正在使用的较新的 Az 模块,这导致它中断。 Az 模块中是否有“ExecuteBatch”的相应方法?

【问题讨论】:

    标签: powershell azure-table-storage azure-rm az


    【解决方案1】:

    根据我的测试,如果我们使用新的 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      • 2019-08-16
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多