我正在尝试使用Get-AzTableRow
来检索Azure表行,然后对其进行更新。但是该cmdlet引发以下错误:
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
这里的任何线索都会有所帮助。
答案 0 :(得分: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')"`
Additional Documentation reference
希望这会有所帮助。