0

I want to extract the data from Azure Table Storage to a CSV file with PowerShell 7.1.4

Here is my PS script :

$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)

I get the following error :

> $data = $table.CloudTable.ExecuteQuery($query)
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find an overload for "ExecuteQuery" and the argument count: "1".
1
  • added Aztable as update Commented Jan 13, 2022 at 16:23

1 Answer 1

1

Cannot find an overload for “Insert” and the argument count: “1”.

Cannot find an overload for “ExecuteQuery” and the argument count: “1”.

The above error occurs when you have both the Azure.Storage and Az.Storage modules loaded at the same time. There are two different versions of the DLL file Microsoft.WindowsAzure.Storage.dll. In some cases, it would use the Azure and in other cases it would use the Az one. The problem is that the Azure.Storage module is required to query or write to a storage table.

As a workaround ,you need to force any query and entity objects to use the same version of the Microsoft.WindowsAzure.Storage.dll file, as the Azure.Storage module. You can do this by saving the version information to a variable, and then specifying it when you create these objects.

You can try with below where we create the $assemblySN variable with the assembly’s full name. Then , we add that to the New-Object command for creating the query object from the TableQuery class. :

$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)

For more information you can refer the blog by Matthew Dowst.

Update:

If the Issue still occurs then you can use Aztable module like :

$cloudTable = (Get-AzStorageTable –Name $table -Context $Ctx).CloudTable 
$data = Get-AzTableRow -table $cloudTable -customFilter "PartitionKey eq '$filedate'"
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks, when I used this code, it gives: $query = New-Object "Microsoft.WindowsAzure.Storage.Table.TableQuery, … Cannot find type [Microsoft.WindowsAzure.Storage.Table.TableQuery,System.Private.CoreLib, | Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]: verify that the assembly containing this type is loaded.
> Get-Module : Az.Accounts (2.7.0) | Az.Storage (4.1.0)
@admin, please run this command first : Install-Module -Name Azure.Storage and then use the code . let me know if you get any other error
already executed this command, the same error is displayed. When I run get-module it just gives Az.Storage 2.7.0 but not Azure.Storage, normal ? Import-Module -Name Azure.Storage ==> Assembly with same name is already loaded
@admin, if the above is not working then can you try using Aztable module . you can refer this Microsoft documention : learn.microsoft.com/en-us/azure/storage/tables/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.