Azure 函数 - Powershell 和 Azure 存储 table(插入或替换)
Azure Function - Powershell and Azure storage table (INSERT OR REPLACE)
我通常使用 node 来编写我的函数,但这需要在 powershell 中。
我正在尝试将数据写入 Azure 存储 Table,但如果数据存在,它不会用以下代码替换它:
Push-OutputBinding -Name outputTable -Value @{
PartitionKey = $PartitionKey
RowKey = $RowKey
Description = $description
}
我一直在到处寻找(文档和 google),但是如果该行存在,我找不到替换该行内容的方法,基本上我想执行相同的替换插入我在节点中。
感谢您的帮助!
根据您的需要,您可以使用Insert Or Merge
操作。该操作将更新现有实体或插入新实体(如果 table 中不存在)。关于如何使用powershell在Azure function中实现,请参考以下步骤
- 安装模块
请在要求中添加一个 'Az' = '5.*' 密钥对.psd1
- 脚本
import-module Az.Storage
$e = New-Object Microsoft.Azure.Cosmos.Table.DynamicTableEntity("Jim","test")
$pro= New-Object Microsoft.Azure.Cosmos.Table.EntityProperty("test")
$pros = New-Object 'System.Collections.Generic.Dictionary[String,Microsoft.Azure.Cosmos.Table.EntityProperty]'
$pros.add("Description",$pro)
$e.Properties=$pros
$aaccountName="andyprivate"
$accountkey="h4pP1fe****U8CacyVMlTWAUA5A=="
$tableName="test"
$ctx =New-AzStorageContext -StorageAccountName $aaccountName -StorageAccountKey $accountkey
$table=Get-AzStorageTable -Name $tableName -Context $ctx
[Microsoft.Azure.Cosmos.Table.TableOperation]$tableOperation=[Microsoft.Azure.Cosmos.Table.TableOperation]::InsertOrMerge($e)
$table.CloudTable.Execute($tableOperation)
在我的 post 评论中使用了 Mike 建议的 https://docs.microsoft.com/en-us/azure/storage/tables/table-storage-how-to-use-powershell#updating-entities!
适用于 foreach 循环,如果您使用正则表达式进行匹配,请小心。
我通常使用 node 来编写我的函数,但这需要在 powershell 中。
我正在尝试将数据写入 Azure 存储 Table,但如果数据存在,它不会用以下代码替换它:
Push-OutputBinding -Name outputTable -Value @{
PartitionKey = $PartitionKey
RowKey = $RowKey
Description = $description
}
我一直在到处寻找(文档和 google),但是如果该行存在,我找不到替换该行内容的方法,基本上我想执行相同的替换插入我在节点中。
感谢您的帮助!
根据您的需要,您可以使用Insert Or Merge
操作。该操作将更新现有实体或插入新实体(如果 table 中不存在)。关于如何使用powershell在Azure function中实现,请参考以下步骤
- 安装模块
请在要求中添加一个 'Az' = '5.*' 密钥对.psd1
- 脚本
import-module Az.Storage
$e = New-Object Microsoft.Azure.Cosmos.Table.DynamicTableEntity("Jim","test")
$pro= New-Object Microsoft.Azure.Cosmos.Table.EntityProperty("test")
$pros = New-Object 'System.Collections.Generic.Dictionary[String,Microsoft.Azure.Cosmos.Table.EntityProperty]'
$pros.add("Description",$pro)
$e.Properties=$pros
$aaccountName="andyprivate"
$accountkey="h4pP1fe****U8CacyVMlTWAUA5A=="
$tableName="test"
$ctx =New-AzStorageContext -StorageAccountName $aaccountName -StorageAccountKey $accountkey
$table=Get-AzStorageTable -Name $tableName -Context $ctx
[Microsoft.Azure.Cosmos.Table.TableOperation]$tableOperation=[Microsoft.Azure.Cosmos.Table.TableOperation]::InsertOrMerge($e)
$table.CloudTable.Execute($tableOperation)
在我的 post 评论中使用了 Mike 建议的 https://docs.microsoft.com/en-us/azure/storage/tables/table-storage-how-to-use-powershell#updating-entities!
适用于 foreach 循环,如果您使用正则表达式进行匹配,请小心。