0

I have a script to update the entities in table storage (https://learn.microsoft.com/en-us/azure/storage/tables/table-storage-how-to-use-powershell#updating-entities):

[string]$filter = `
    [Microsoft.Azure.Cosmos.Table.TableQuery]::GenerateFilterCondition("Period",`
    [Microsoft.Azure.Cosmos.Table.QueryComparisons]::Equal,6)
    
    $users = Get-AzTableRow `
    -table $cloudTable `
    -customFilter $filter
    
    foreach ($user in $users)
    {
        $user.Period = 24
        $user | Update-AzTableRow -table $cloudTable
    }

This doesn't work. What am I missing?

user989988
  • 3,006
  • 7
  • 44
  • 91

1 Answers1

0

I tried in my environment and successfully updated the period in the entities:

I followed this MS-DOCS to add the four table entities to table storage in my environment.

Code:

$storageTable = Get-AzStorageTable –Name $tableName –Context $ctx

$cloudTable = $storageTable.CloudTable

$partitionKey1 = "partition1"
$partitionKey2 = "partition2"

# add four rows 
Add-AzTableRow `
    -table $cloudTable `
    -partitionKey $partitionKey1 `
    -rowKey ("CA") -property @{"Period"= "2";"userid"=1}

Add-AzTableRow `
    -table $cloudTable `
    -partitionKey $partitionKey2 `
    -rowKey ("NM") -property @{"Period"="7";"userid"=2}

Add-AzTableRow `
    -table $cloudTable `
    -partitionKey $partitionKey1 `
    -rowKey ("WA") -property @{"Period"="13";"userid"=3}

Add-AzTableRow `
    -table $cloudTable `
    -partitionKey $partitionKey2 `
    -rowKey ("TX") -property @{"Period"="15";"userid"=4}

Get-AzTableRow -table $cloudTable | ft 

Get-AzTableRow -table $cloudTable -partitionKey $partitionKey1 | ft

Output:

enter image description here

To update entity:

# Create a filter and get the entity to be updated.
[string]$filter = `
    [Microsoft.Azure.Cosmos.Table.TableQuery]::GenerateFilterCondition("Period",`
    [Microsoft.Azure.Cosmos.Table.QueryComparisons]::Equal,"7")
$user = Get-AzTableRow `
    -table $cloudTable `
    -customFilter $filter

$user.Period ="24"

# 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 "(Period eq '24')"

The above command executed successfully and updated Period 7 to 24.

Console:

enter image description here

Venkatesan
  • 3,748
  • 1
  • 3
  • 15