I have a requirement to load the variables inside a variable group into an azure keyvault. We do not want to link the variable group to the keyvault in order to be able to close the keyvault external network access.
So I started developing a powershell script that lists the variable group variables using az cli devops extension and stores it into a powershell var.
Then I iterate for each var and try to build the var name in Azure Devops format $(var) so I can use it with Set-AzKeyVaultSecret.
The problem: It seems the variable name has to be hardcoded for the Azure Devops pipeline to be able to convert it to it's real value.
Example:
$pipelineVarEnc = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$('variablename')"))
Does not work:
$Name = $var.Name
$command = '$pipelineVarEnc = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$(' + $Name + ')"))'
Invoke-command $command
Anyone knows how to bypass this issue?