Private/Set-InfrastructureStorageData.ps1

# Will be called in VM
function Global:Set-InfrastructureStorageData {
    [CmdletBinding()]
    <#
    .SYNOPSIS
        ...
        maybe obsolete
    .DESCRIPTION
        ...
    #>

    param(
        [Parameter(Mandatory = $true)]
        [string]
        $ResourceGroupName,        
        [Parameter(Mandatory = $true)]
        [string]
        $ResourceLocation,
        [Parameter(Mandatory = $true)]
        [string]
        $StorageAccountName,
        [Parameter(Mandatory = $true)]
        [string]
        $TableName,
        [Parameter(Mandatory = $false)]
        [string]
        $ApplicationServerLoadBalancerIP,
        [Parameter(Mandatory = $false)]
        [string]
        $DnsIdentity
    )
    process {
        Write-CustomHost -Message "Updating Infrastructure storage data..."

        $storageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName
        $storageAccountContext = $storageAccount.Context
        $storageAccountTable = Get-AzStorageTable -Name $TableName -Context $StorageAccountContext
        $table = $storageAccountTable.CloudTable

        # Save previous values if new ones are empty
        $row = Get-AzTableRow -Table $table
        if ([string]::IsNullOrEmpty($DnsIdentity)){
            $DnsIdentity = $row.DnsIdentity
        }
        if ([string]::IsNullOrEmpty($ApplicationServerLoadBalancerIP)){
            $ApplicationServerLoadBalancerIP = $row.ApplicationServerLoadBalancerIP
        }

        $properties = @{
            "ApplicationServerLoadBalancerIP" = $ApplicationServerLoadBalancerIP
            "DnsIdentity"                     = $DnsIdentity
        }

        $params = @{
            Table          = $table
            PartitionKey   = 0
            RowKey         = 0
            property       = $properties
            UpdateExisting = $true
        }
        Add-AzTableRow @params
    }
}