【问题标题】:AzureTable with Powershell : Cannot find an overload for "ExecuteQuery" and the argument count: "1"AzureTable with Powershell:找不到“ExecuteQuery”的重载和参数计数:“1”
【发布时间】:2021-12-31 09:31:05
【问题描述】:

我想使用 PowerShell 7.1.4 将数据从 Azure 表存储提取到 CSV 文件

这是我的 PS 脚本:

$StorageAccountName = "" 
$StorageAccountKey = "" 
$table = ""

$Ctx = New-AzureStorageContext –StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey 

$table = Get-AzureStorageTable –Name $TableName -Context $Ctx

$query = New-Object "Microsoft.WindowsAzure.Storage.Table.TableQuery" 

$query.FilterString = "(Timestamp ge datetime'2021-12-30T06:00:00Z' and Timestamp lt datetime'2021-12-30T12:00:00Z')"

$data = $table.CloudTable.ExecuteQuery($query)

我收到以下错误:

> $data = $table.CloudTable.ExecuteQuery($query)
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find an overload for "ExecuteQuery" and the argument count: "1".

【问题讨论】:

  • 将 Aztable 添加为更新

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


【解决方案1】:

找不到“插入”的重载和参数计数:“1”。

找不到“ExecuteQuery”和参数计数的重载: “1”。

当您同时加载Azure.StorageAz.Storage 模块时会发生上述错误。 DLL 文件Microsoft.WindowsAzure.Storage.dll 有两个不同版本。在某些情况下,它会使用Azure,而在其他情况下,它会使用Az。问题是需要Azure.Storage模块来查询或写入存储表。

作为一种解决方法,您需要强制任何查询和实体对象使用与Azure.Storage 模块相同版本的Microsoft.WindowsAzure.Storage.dll 文件。为此,您可以将版本信息保存到一个变量中,然后在创建这些对象时指定它。

您可以在下面尝试使用程序集的全名创建 $assemblySN 变量。然后,我们将其添加到New-Object 命令中,用于从TableQuery 类创建查询对象。 :

$Ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$table = Get-AzureStorageTable -Name $TableName -Context $Ctx
#get the $table Assembly FullName
$assemblySN = $table.CloudTable.GetType().Assembly.FullName
#Create a table query.
$query = New-Object -TypeName  "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
$query.FilterString = "(Timestamp ge datetime'2021-12-30T06:00:00Z' and Timestamp lt datetime'2021-12-30T12:00:00Z')"
$entities = $table.CloudTable.ExecuteQuery($query)

有关详细信息,您可以参考 Matthew Dowstblog

更新:

如果问题仍然存在,那么您可以使用 Aztable module,例如:

$cloudTable = (Get-AzStorageTable –Name $table -Context $Ctx).CloudTable 
$data = Get-AzTableRow -table $cloudTable -customFilter "PartitionKey eq '$filedate'"

【讨论】:

  • 谢谢,当我使用这段代码时,它给出: $query = New-Object "Microsoft.WindowsAzure.Storage.Table.TableQuery, ... 找不到类型 [Microsoft.WindowsAzure.Storage.Table.TableQuery ,System.Private.CoreLib, | Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]:验证是否加载了包含此类型的程序集。
  • > 获取模块:Az.Accounts (2.7.0) | Az.Storage (4.1.0)
  • @admin,请先运行此命令:Install-Module -Name Azure.Storage,然后使用代码。如果您遇到任何其他错误,请告诉我
  • 已经执行了这个命令,同样报错。当我运行 get-module 时,它​​只提供 Az.Storage 2.7.0 而不是 Azure.Storage,正常吗? Import-Module -Name Azure.Storage ==> 同名程序集已加载
  • @admin,如果上述方法不起作用,那么您可以尝试使用 Aztable 模块。你可以参考这个微软文档:docs.microsoft.com/en-us/azure/storage/tables/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-09
  • 1970-01-01
  • 1970-01-01
  • 2012-07-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多