bli*_*inn 3 powershell azure-table-storage azure-powershell
我需要在通过Azure PowerShell 模块更新记录时向 Azure 表存储实体添加新属性。我希望通过更新来实现这一点,而不是删除/添加新实体。
我当前拥有的脚本紧密遵循 Microsoft 的更新实体示例,并且非常适合更新现有属性。下面是他们示例的修改版本,我尝试添加新的“昵称”属性。
$user = Get-AzTableRow -table $cloudTable -customFilter $filter
# Change the entity.
$user.username = "Jessie2"
# Attempting to add a new property
$user.nickname= "Jess"
# To commit the change, pipe the updated record into the update cmdlet.
$user | Update-AzTableRow -table $cloudTable
Run Code Online (Sandbox Code Playgroud)
正如您所料,PowerShell 会抛出错误,因为该行没有现有的昵称属性:
Exception setting "nickname": "The property 'nickname' cannot be found on this object. Verify that the property exists and
can be set.
删除/创建新实体是添加新属性的唯一方法吗?
他在博客文章中表示,他将行条目转换为 PSCustomObjects,因此像这样对待它并用于Add-Member添加新属性是有意义的。尝试改变
$user.nickname= "Jess"
Run Code Online (Sandbox Code Playgroud)
到
Add-Member -InputObject $user -NotePropertyName 'nickname' -NotePropertyValue 'Jess'
Run Code Online (Sandbox Code Playgroud)
或更短的
$user|add-member 'nickname' 'Jess'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2444 次 |
| 最近记录: |