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.

4

1 回答 1

0

查看以下脚本以设置存储上下文并使用 cloudtable 读取表行并更新它。

#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')"`

附加文档参考

希望这可以帮助。

于 2019-06-14T16:23:38.833 回答