【问题标题】:PowerShell: Using PS to get entities (row) from an Azure Table Storage to populate another tablePowerShell:使用 PS 从 Azure 表存储中获取实体(行)以填充另一个表
【发布时间】:2021-10-21 10:32:37
【问题描述】:

案例: 我在 Azure 表存储中有 3 个表(表 1、表 2、表 3)。

表 1 中的实体(行)在 ADO 发布管道运行后填充。 Table2 实体(10 行)是需要分配给 Table1 中填充的每个实体的所有规则/Azure 策略,并且每个 Table1 条目的所有 10 条规则都必须填充到 Table3 中

【问题讨论】:

    标签: azure azure-table-storage


    【解决方案1】:

    下面是从一个表中获取行并插入到 Azure 表存储中的另一个的示例。您可以根据需要通过包含更多表来更改它:

    获取azure Table Storage的上下文:

    New-AzStorageContext -StorageAccountName "<yourstorageacc>" -StorageAccountKey "<youraccountkey>"
    

    获取第一个表的引用:

    $cloudTable = (Get-AzStorageTable –Name "table1" –Context $ctx).CloudTable
    

    获取需要插入另一个表的记录。相应地更改过滤器:

    [string]$filter = `
        [Microsoft.Azure.Cosmos.Table.TableQuery]::GenerateFilterCondition("username",`
        [Microsoft.Azure.Cosmos.Table.QueryComparisons]::Equal,"Jessie")
    $user = Get-AzTableRow `
        -table $cloudTable `
        -customFilter $filter
    

    获取第二个表的引用:

    $cloudTable2 = (Get-AzStorageTable –Name "table2" –Context $ctx).CloudTable
    

    使用我们检索到的相同 $user 对象将记录插入到第二个表中。

    Add-AzTableRow `
        -table $cloudTable2 `
        -partitionKey $partitionKey1 `
        -rowKey ("CA") -property @{"username"=$user.username;"userid"=$user.userid}
    

    您可以根据需要插入/更新。

    参考文章:Perform Azure Table storage operations with Azure PowerShell

    【讨论】:

    • 非常感谢@AnuragSharma-MSFT。最后一部分绝对是它的工作方式。但是,我必须首先使用“ForEach”来遍历 Table2 中的每个条目(10)。因此,它选择 Table2 中的第一个条目,将其分配给填充到 Table1 的条目,将其发送到 Table3,然后对 Table2 中的所有条目重复。
    猜你喜欢
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    • 2022-11-09
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多