Reputation: 1724
I am trying to get all rows in an Azure storage table using these PoserShell commands:
$saContext = (AzureRmStorageTable\Get-AzureRmStorageAccount -Name $storageAccount -ResourceGroupName $resourceGroup).Context
$table = Get-AzureStorageTable -Name $tableName -Context $saContext
Get-AzureStorageTableRowAll -table $table
but it will return this error:
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
I even used these line of commands too but all will return same error:
#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
do you know how I can get a row in Azure Storage tables using PowerShell?
indeed, I have installed AzureRmStorageTable
from here.
Upvotes: 4
Views: 7533
Reputation: 2958
Here is the answer how to get all rows using new Az commands, AzTable module is needed.
$storageAccountName = "name"
$storageAccountKey = "key=="
$context = New-AzStorageContext $storageAccountName -StorageAccountKey $storageAccountKey
$cloudTable = (Get-AzStorageTable –Name "table_name" –Context $context).CloudTable
Get-AzTableRow -Table $cloudTable
Retrieve rows with a filter:
[string]$filter = "Timestamp lt datetime'2019-05-27T13:58:04.0587693+02:00'"
Get-AzTableRow -Table $cloudTable -CustomFilter $filter
More dcumentation from Azure https://learn.microsoft.com/bs-latn-ba/azure/storage/tables/table-storage-how-to-use-powershell
Upvotes: 3
Reputation: 1925
This is the result of differering dll versions in powershell modules Azure.Storage and AzureRm.Storage. AzureRm.Storage has an older version of Microsoft.WindowsAzure.Storage.dll than the version in Azure.Storage, and lacks functionality. Once both assemblies are loaded, there's not a great way of telling powershell which one to use.
See the issue here: https://github.com/Azure/azure-powershell/issues/5030
I can think of three workarounds:
1) as mentioned in the link, you can use New-Object to create powershell objects specifying the assembly version. E.g.:
$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) Create a compiled class in powershell to handle your direct .net interaction. The command Add-Type creates your class, and you can reference the correct dll in the -ReferencedAssemblies parameter. There's a simple example of c# in powershell here: http://activedirectoryfaq.com/2016/01/use-net-code-c-and-dlls-in-powershell/. This option worked best for me.
3) Copy the newer version of Microsoft.WindowsAzure.Storage.dll from the Azure.Storage module directory to the AzureRm.Storage module directory. This is obviously a fragile option, but probably the easiest quick fix.
Upvotes: 2
Reputation: 1724
I found that the error is because of some problem in AzureRmStorageTable V1.0.0.17. I have updated it to V1.0.0.20, and it's working now. In documentation of V1.0.0.20, they wrote: 'Implemented some measures in order to avoid conflicts between different assembly versions, more specifically Microsoft.WindowsAzure.Storage.Dll.'
I can't remember that which version was installed on the Runbooks by default, anyway, it will work if you update it.
Thanks
Upvotes: 1