Sayantan Ghosh
Sayantan Ghosh

Reputation: 1056

Cannot find an overload for “ExecuteQuerySegmentedAsync” and the argument count: “2” in Get-AzTableRow

I am trying use the Get-AzTableRow to retrieve a Azure Table row, followed by updating it. But the cmdlet is throwing the below errors:

  PS C:\WINDOWS\system32> Get-AzTableRow -ColumnName "NsgName" -Value "subnet1invnet4-nsg" -Operator "Equal"
  You cannot call a method on a null-valued expression.
  At C:\Users\sayghosh\Documents\WindowsPowerShell\Modules\AzTable\2.0.2\AzureRmStorageTableCoreHelper.psm1:52 char:4
   +             $Results = $Table.ExecuteQuerySegmentedAsync($TableQuery, ...
   +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
   + FullyQualifiedErrorId : InvokeMethodOnNull

PS C:\WINDOWS\system32> Get-AzTableRow -table $storageCloudTable
Cannot find an overload for "ExecuteQuerySegmentedAsync" and the argument count: "2".
At C:\Users\sayghosh\Documents\WindowsPowerShell\Modules\AzTable\2.0.2\AzureRmStorageTableCoreHelper.psm1:52 char:4
 +             $Results = $Table.ExecuteQuerySegmentedAsync($TableQuery, ...
 +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo          : NotSpecified: (:) [], MethodException
 + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Any lead here will be helpful.

Upvotes: 0

Views: 805

Answers (1)

bharathn-msft
bharathn-msft

Reputation: 972

Check out the below script to set the storage context and using cloudtable to read the table row and updating it.

#To install the AzTable module if not already installed
#Install-Module AzTable
#set the subscription contenxt if not already set
#Set-AzContext -Subscription "Subscription Name"

$storageAccountName = "storageaccountName"
$tableName = "storagetableName"
$partitionKey1 = "partitionKey"
$resourceGroup = "ResourceGroup Name"


$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name  $storageAccountName

# Get the Storage Contenxt
$ctx = $storageAccount.Context

# Usage of CloudTable is mandatory when working with AzTable PowerShell module.
$cloudTable = (Get-AzStorageTable -Name $tableName -Context $ctx ).CloudTable

# different ways to get the table row
#Get-AzTableRow -table $cloudTable -customFilter "(username eq 'bob2')"
#Get-AzTableRow -Table $cloudTable -ColumnName "username" -Value "bob2" -Operator Equal

#Create a filter and get the entity to be updated.
[string]$filter =    [Microsoft.Azure.Cosmos.Table.TableQuery]::GenerateFilterCondition("username",       
[Microsoft.Azure.Cosmos.Table.QueryComparisons]::Equal,"bob2")

$user = Get-AzTableRow  -table $cloudTable -customFilter $filter

# Change the entity.
$user.username = "james"

# To commit the change, pipe the updated record into the update cmdlet.
$user | Update-AzTableRow -table $cloudTable

# To see the new record, query the table.
Get-AzTableRow -table $cloudTable -customFilter "(username eq 'james')"`

Additional Documentation reference

Hope this helps.

Upvotes: 1

Related Questions