如何使用PowerShell在Azure存储表中获取一行?

问题描述 投票:2回答:2

我试图使用这些PowerShell命令获取Azure存储表中的所有行:

$saContext = (AzureRmStorageTable\Get-AzureRmStorageAccount -Name $storageAccount -ResourceGroupName $resourceGroup).Context
$table = Get-AzureStorageTable -Name $tableName -Context $saContext
Get-AzureStorageTableRowAll -table $table

但它会返回此错误:

Cannot find an overload for "ExecuteQuery" and the argument count: "1".
At C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\1.0.0.17\AzureRmStorageTableCoreHelper.psm1:305 char:6
+         $result = $table.CloudTable.ExecuteQuery($tableQuery)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

我甚至使用了这些命令行,但所有命令都会返回相同的错误:

#Get-AzureStorageTableRowByColumnName -columnName "Average" -operator Equal -table $table -value 3228132966.4
#Get-AzureStorageTableTable -resourceGroup $resourceGroup -storageAccountName $storageAccount -tableName $tableName
#Get-AzureStorageTableRowAll -table $table | ft
#Get-AzureStorageTableRowByPartitionKey -table $table –partitionKey “I-Used-One-Of-My-Partition-Keys-From-Table” | ft

你知道如何使用PowerShell在Azure存储表中获取一行吗? 事实上,我已经从AzureRmStorageTable安装了here

powershell azure azure-storage azure-table-storage
2个回答
1
投票

我发现该错误是由于AzureRmStorageTable V1.0.0.17中的一些问题。我已将其更新到V1.0.0.20,现在它正在运行。在V1.0.0.20的文档中,他们写道:'实施了一些措施,以避免不同程序集版本之间的冲突,更具体地说是Microsoft.WindowsAzure.Storage.Dll。

我不记得默认情况下在Runbook上安装了哪个版本,无论如何,如果你更新它,它将会起作用。

谢谢


1
投票

这是在PowerShell模块Azure.Storage和AzureRm.Storage中区分dll版本的结果。 AzureRm.Storage的旧版本的Microsoft.WindowsAzure.Storage.dll比Azure.Storage中的版本低,并且缺少功能。一旦加载了两个程序集,就没有一种方法可以告诉powershell使用哪个程序集。

请参阅此处的问题:https://github.com/Azure/azure-powershell/issues/5030

我可以想到三个解决方法:

1)如链接中所述,您可以使用New-Object创建指定程序集版本的powershell对象。例如。:

$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $key
$sasToken = New-AzureStorageTableSASToken -Context $ctx -Permission a -Name $StorageTableName
$sasURI = $ctx.TableEndpoint + $StorageTableName + $sasToken
$cloudTable = New-Object -typename "Microsoft.WindowsAzure.Storage.Table.CloudTable, Microsoft.WindowsAzure.Storage, Version=8.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" -ArgumentList $sasURI

2)在powershell中创建一个编译类来处理直接的.net交互。命令Add-Type创建您的类,您可以在-ReferencedAssemblies参数中引用正确的dll。在这里有一个简单的例子:powerhell:http://activedirectoryfaq.com/2016/01/use-net-code-c-and-dlls-in-powershell/。这个选项最适合我。

3)将较新版本的Microsoft.WindowsAzure.Storage.dll从Azure.Storage模块目录复制到AzureRm.Storage模块目录。这显然是一个脆弱的选择,但可能是最简单的快速修复。

© www.soinside.com 2019 - 2024. All rights reserved.