簡體   English   中英

Powershell的更新實體命令用於蔚藍表存儲

[英]Powershell's Update Entity command for azure table storage

我需要一些在Powershell中使用天藍色表存儲的示例或教程。 我知道如何創建表,插入實體和顯示實體。 但是,任何人都可以給我關於更新案例的任何指導。 如何在Powershell中更新表中的現有實體? 如何在Powershell中的表中檢查/訪問實體的特定列?

添加實體的腳本:

function InsertRow($table, [String]$partitionKey, [String]$rowKey, [int]$intValue)
{
  $entity = New-Object "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" $partitionKey, $rowKey
  $entity.Properties.Add("IntValue", $intValue)
  $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity))
}

$StorageAccountName = "storageName"
$StorageAccountKey = "StorageKey"

$context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

$tablename = "test"

$table = Get-AzureStorageTable $tablename -Context $context -ErrorAction Ignore
if ($table -eq $null)
{
    New-AzureStorageTable $tablename -Context $context
}

for ($p = 1; $p -le 1; $p++)
{
  for ($r = 1; $r -le 1; $r++)
  {
    InsertRow $table "P$p" "R$r" $r
  }
}

顯示表中所有實體的腳本:

$query = New-Object Microsoft.WindowsAzure.Storage.Table.TableQuery

#Define columns to select.
$list = New-Object System.Collections.Generic.List[string]
$list.Add("RowKey")
$list.Add("IntValue")

#Set query details.
$query.SelectColumns = $list
$query.TakeCount = 20

#Execute the query.
$entities = $table.CloudTable.ExecuteQuery($query)

#Display entity properties with the table format.
$entities  | Format-Table PartitionKey, RowKey, @{ Label = "IntValue"; Expression={$_.Properties["IntValue"].Int32Value}} -AutoSize

我還需要命令來更新特定實體。 有幫助嗎?

得到它了。 通過執行$entity.Properties["IntValue"].Int32Value更改實體的值,然后使用此命令更新該實體:

$result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::InsertOrReplace($entity))

$Query.FilterString可用於從表中獲取特定實體。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM