Public/Update-AzTableAPIEntity.ps1
|
function Update-AzTableAPIEntity { <# .SYNOPSIS Merges properties into an existing entity in Azure Table Storage. .DESCRIPTION Performs an HTTP PATCH (OData merge). Only the properties supplied in the Entity parameter are written; existing properties not present in the update are preserved. The entity must already exist. Use Set-AzTableAPIEntity for a full replace (PUT). .PARAMETER Context Connection context created by New-AzTableAPIContext. .PARAMETER TableName Name of the target table. .PARAMETER Entity Hashtable or PSCustomObject containing the properties to update. Must include PartitionKey and RowKey. .PARAMETER ETag Optional ETag for optimistic concurrency. Defaults to '*' (unconditional). .PARAMETER PassThru When specified, returns a PSCustomObject containing the ETag returned by the service. Useful for subsequent optimistic-concurrency operations. .EXAMPLE $update = @{ PartitionKey = 'Sales'; RowKey = '001'; Status = 'Shipped' } Update-AzTableAPIEntity -Context $ctx -TableName 'Orders' -Entity $update .EXAMPLE Update-AzTableAPIEntity -Context $ctx -TableName 'Orders' -Entity $update -ETag 'W/"datetime'"'"'2024-01-01T00%3A00%3A00.0000000Z'"'"'"' .EXAMPLE $result = Update-AzTableAPIEntity -Context $ctx -TableName 'Orders' -Entity $update -PassThru $result.ETag #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] [OutputType([PSCustomObject])] param ( [Parameter(Mandatory)] [ValidateScript({ ($_.PSObject.Properties.Name -contains 'Endpoint') -and ($_.PSObject.Properties.Name -contains 'AuthType') }, ErrorMessage = 'The -Context parameter requires a context object created by New-AzTableAPIContext.')] [PSCustomObject]$Context, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$TableName, [Parameter(Mandatory)] [ValidateNotNull()] [object]$Entity, [string]$ETag = '*', [switch]$PassThru ) $entityKeys = Get-AzTableEntityKey -Entity $Entity $pk = $entityKeys.PartitionKey $rk = $entityKeys.RowKey $resource = Format-AzTableEntityResource -TableName $TableName -PartitionKey $pk -RowKey $rk if ($PSCmdlet.ShouldProcess("$TableName / PartitionKey='$pk', RowKey='$rk'", 'Update entity in Azure Table Storage')) { $response = Invoke-AzTableRestMethod -Context $Context -Method 'PATCH' -Resource $resource -Body $Entity -ETag $ETag if ($PassThru) { $responseETag = $response.Headers['ETag'] if ($responseETag -is [array]) { $responseETag = $responseETag[0] } return [PSCustomObject]@{ ETag = $responseETag } } } } |