【问题标题】:Getting "The remote server returned an error: (409) Conflict." when trying to add rows into azure table获取“远程服务器返回错误:(409)冲突。”尝试将行添加到天蓝色表时
【发布时间】:2018-07-22 11:08:26
【问题描述】:

我正在尝试使用 PowerShell 上传 azure 表格行,但收到​​以下错误。这可能是由于错误的 Azure 存储 powershell 模块造成的吗?我正在使用 Azure.Storage 4.0.2 模块。

以下是代码:

# Getting all the resource group
$resource_group_list = Get-AzureRmResourceGroup

# Iterating through the resource group
foreach($resource_group_list_iterator in $resource_group_list){

    # Since the solution applies for virtual machines,
    # obtain the list of virtual machines for the resource group
    $virtual_machine_list = get-azurermvm -ResourceGroupName $resource_group_list_iterator.ResourceGroupName

    # Proceed only when resource group contains virtual machines
    if(!($virtual_machine_list -eq $null)){

        # Iterate through the virtual machine list
        foreach($virtual_machine_list_iterator in $virtual_machine_list){

            # Creat an unique ID by concatinating 'Resource Group name' and 'Virtual Machine name'
            $unique_id = $resource_group_list_iterator.ResourceGroupName + "__" + $virtual_machine_list_iterator.name
            Write-Host $unique_id

            # Obtain the tags associated with the virtual machines
            $virtual_machine_tags = (get-azurermvm -ResourceGroupName $resource_group_list_iterator.ResourceGroupName -Name $virtual_machine_list_iterator.name).Tags

            # Iterate over the tags to match the tag that we are looking for
            foreach($tag_iterator in $virtual_machine_tags){
    if($tag_iterator.keys -eq 'owner' -and $tag_iterator.values -eq 'ibm'){

        # Store the tags in a variable to later store it in Azure table
        $virtual_machine_tag = $tag_iterator.keys.ToString()
        $virtual_machine_value = $tag_iterator.Values.ToString()


        $partitionKey1 = $unique_id
        if($virtual_machine_tag -eq $null) {$virtual_machine_tag = $null}
        if($virtual_machine_value -eq $null) {$virtual_machine_value = $null}

    $hash = @{}
    $hash.Add('uniqueid',$unique_id)
    $hash.Add('key',$virtual_machine_tag)
    $hash.add('value',$virtual_machine_value)

    Add-StorageTableRow `
    -table $azure_table_object `
    -partitionKey $partitionKey1 `
    -rowKey ("CA") `
     -property $hash

        #Write-Output "Key: " $tag_iterator.keys
        #Write-Output "Value: " $tag_iterator.Values
    }
}


            #Write-Host "Tags: " $virtual_machine_tags
            #Write-Host " "
        }


    }


}

以下是我收到的异常:

Exception calling "Execute" with "1" argument(s): "The remote server returned an 
error: (409) Conflict."
At C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\1.0.0.21\AzureRmS
torageTableCoreHelper.psm1:267 char:16
+ ...      return ($table.CloudTable.Execute((invoke-expression "[Microsoft ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : StorageException

我已经浏览了一些有关如何排除故障的在线资源,但我没有得到任何解决方案。

【问题讨论】:

  • 如果您尝试添加与现有行具有相同分区和行键的行,通常会返回 409。

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


【解决方案1】:

正如 junnas 提到的,409 错误意味着添加与现有行具有相同分区键和行键的行。

您可以在插入表格之前打印partition Key and row key。如果要获取unique_id,我们可以使用Guid,请尝试使用$unique_id = $resource_group_list_iterator.ResourceGroupName + "__" + $virtual_machine_list_iterator.name+[guid]::newguid()

注意:在您的情况下,我建议您可以将值 CA 用作分区键,将 $unique_id 用作行键。

【讨论】:

  • 谢谢你,汤姆。代码现在工作得很好。但是,“键”和“值”插入为:“”System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.String“”。你知道为什么吗?如果我删除“tostring()”方法,我会得到一个异常——>找不到“Add”的重载和参数计数:“2”。在 C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\1.0.0.21\AzureRmStorageTableCoreHelper.psm1:260 char:4
猜你喜欢
  • 1970-01-01
  • 2014-03-22
  • 2017-12-09
  • 1970-01-01
  • 2022-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多