找不到“执行”和参数计数:“ 1”的重载。无法插入天蓝色的存储表

时间:2019-05-23 11:12:07

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

我有一个Powershell脚本可以将数据上传到Azure存储表中。 Powershell脚本如下所示:


$StorageAccountName = "xxx" 
$StorageAccountKey = "xxxxx"
$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$tableName = "ProvisioningRecord"
$table = Get-AzStorageTable –Name $tableName -Context $ctx

Add-Entity -table $table -partitionKey abc -rowKey xyz


function Add-Entity { 
   [CmdletBinding()] 

   param( 
      $table, 
      [String]$partitionKey, 
      [String]$rowKey 

   )  


   $entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" -ArgumentList $partitionKey, $rowKey 

   $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity)) 

}

我得到了错误:

Cannot find an overload for "Execute" and the argument count: "1".
At line:1 char:1
+ $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

在此链接之后:我添加了https://www.catapultsystems.com/blogs/azure-storage-powershell-error-cannot-find-an-overload/

$assemblySN = $table.CloudTable.GetType().Assembly.FullName
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
$result = $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::InsertOrReplace(`$entity)"))

它给我一个错误:

New-Object : Cannot find type [Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,Microsoft.Azure.Cosmos.Table, Version=0.10.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]: 
verify that the assembly containing this type is loaded.
At line:1 char:11
+ $entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table. ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

但是经过以上修改(添加$ assemblySN)的相同代码可以在Powershell 5.1.17134.590版中使用。同一脚本在Powershell 5.1.17763.316版本中不起作用。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您使用哪个版本的Az.Storage模块? (运行Get-module进行检查)。

从Az.Storage 1.1.0开始,使用Microsoft.Azure.Cosmos.Table SDK管理表。 (因为新的存储客户端库不再支持表。)

因此,Azure表对象的命名空间从“ Microsoft.WindowsAzure.Storage.Table”更改为“ Microsoft.Azure.Cosmos.Table”。并且您需要相应地在脚本中更改名称空间。

https://github.com/Azure/azure-powershell/issues/8808

中查看更多详细信息