Public/Update-SpecAzTableRow.ps1
function Update-SpecAzTableRow { <# .SYNOPSIS Updates a row in an Azure Table Storage with the specified properties. .DESCRIPTION The Update-SpecAzTableRow function is used to update a row in an Azure Table Storage. You provide the table name, resource group, storage account, and key-value pair for locating the row to update, as well as a list of properties to update or add to the row. .PARAMETER tableName The name of the Azure Table where the row will be updated. .PARAMETER resourceGroup The name of the Azure Resource Group containing the Azure Table. .PARAMETER storageAccount The name of the Azure Storage Account containing the Azure Table. .PARAMETER Key The key to use for locating the row to update. Defaults to 'RowKey'. .PARAMETER Value The value of the key specified by 'Key' to locate the row to update. .PARAMETER PropertyList A hashtable containing properties and their values to update or add to the row. .EXAMPLE $PropertyList = @{ Device_Name = $env:computername DeviceType = 'DeviceType2' Last_Logged_on = '' Date = $NULL } # Filter out the empty fields $PropertyListFilter = @{} foreach ($h in $PropertyList.GetEnumerator()) { if ($h.value) { $PropertyListFilter[$h.name] = $h.value } } # Update the Azure Table row Update-SpecAzTableRow -tableName "YourTableName" -resourceGroup "YourResourceGroup" -storageAccount "YourStorageAccount" -Value "YourRowKeyValue" -PropertyList $PropertyListFilter # This example demonstrates how to send a hashtable that has been filtered to contain only key pairs that have values. # It updates a row in the specified Azure Table with the provided properties. $PropertyFilter will not contain 'Last_Logged_On' or 'Date' in this example, and so those entries will not be updated. # The function will update the row with the properties specified in $PropertyListFilter. .NOTES Author: andy.naftel Version: 1.0 #> [cmdletbinding()] param ( [Parameter(Mandatory = $true)] $tableName, [Parameter(Mandatory = $true)] $TableResourceGroup, [Parameter(Mandatory = $true)] $TableStorageAccount, [Parameter(Mandatory = $False)] $Key = 'RowKey', [Parameter(Mandatory = $true)] $Value, [Parameter(Mandatory = $true)] $PropertyList ) Write-Verbose "Attempting to retrieve data from table $tableName" $cloudTable = get-specCloudtable -TableName $TableName -tableResourceGroup $tableResourceGroup -tableStorageAccount $tableStorageAccount # Create a filter and get the entity to be updated. [string]$filter = ` [Microsoft.Azure.Cosmos.Table.TableQuery]::GenerateFilterCondition($Key, ` [Microsoft.Azure.Cosmos.Table.QueryComparisons]::Equal, $Value) $update = Get-AzTableRow ` -table $cloudTable ` -customFilter $filter Write-Verbose "Updating entries in table $tableName" foreach ($h in $PropertyList.GetEnumerator()) { if ($update.($h.name)) { $update.($h.name) = $h.value $tableresult = $update | Update-AzTableRow -table $cloudTable -ErrorAction SilentlyContinue } else { $update | add-member $h.name $h.value $tableresult = $update | Update-AzTableRow -table $cloudTable -ErrorAction SilentlyContinue } } Return $tableresult } |