public/library/Update-PSTSVariableGroup.ps1

function Update-PSTSVariableGroup
{
    [CmdletBinding(DefaultParameterSetName="set1")]
    param(

        [Parameter(Mandatory=$true)][string] $project,
        [Parameter(Mandatory=$true)][VariableGroup] $variableGroup,
        [parameter(ParameterSetName="set1")] [HashTable] $variables,
        [parameter(ParameterSetName="set2")] [string[]] $vaultKeys

    )

    process {

        $null = @(

            if ($PSCmdlet.ParameterSetName -eq "set2" ) {
                $vaultKeys |  `
                Foreach-Object {
                    $_, $variableGroup.variables.Add( `
                        $_ , `
                        $(_getJSONVariable `
                        -isSecret $true `
                        ) `
                    )
                }
            }
            else
            {
                $variables.GetEnumerator() | `
                 Foreach-Object {
                    $_, $variableGroup.variables.Add( `
                        $_.Key , `
                        $(_getJSONVariable `
                        -isSecret $false `
                        -value $_.Value
                        ) `
                    )
                }
            }

            $content = `
            _PSTSAPI `
                -project $project `
                -resource "distributedtask/VariableGroups/$($variableGroup.id)" `
                -method "PUT" `
                -body $($variableGroup | ConvertTo-Json) `
                -contentType "application/json"

        )
        return [VariableGroup]$content
    }
}