Scoped Variable with Hyphen in its Name

I’m working with an Azure Key Vault integration and, currently, a few secret names with hyphens. To reference such a secret in a script after it has been retrieved from a registered vault and placed inside a PowerShell Universal variable, the syntax is:

$secret:varName

Referencing a secret-containing variable without a hyphen in its name works fine, but a reference to a variable with a hyphen does not. I’ve tried a great variety of alternative syntaxes and none resolve. I’ve also tried using the Get-Variable cmdlet without success. Any ideas here?

You can use this syntax for hyphenated variable names.

${Secret:Test-Variable}
2 Likes