0

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.

1
  • Should you not add hyphens before eq and and in your filter? Commented May 31, 2019 at 11:05

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

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.