Skip to content

Update Get-AzKeyVaultSecret's example for constrained language mode #13496

@isra-fel

Description

@isra-fel

Description

The way our current example converts secure string secret to plain text secret does not work in PowerShell constrained language mode, because

Only allowed types (listed below) can be used in PowerShell. Other types are not permitted.
(See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_language_modes?view=powershell-7.1#constrained-language-constrained-language)

and System.Runtime.InteropServices.Marshal is not in the the list.

@TylerLeonhardt suggested a work-around by using PSCredential class (thanks Tyler!)

$securestr = (Get-AzKeyVaultSecret -Name Foo -VaultName bar).SecretText
[pscredential]::new("DoesntMatter", $securestr).GetNetworkCredential().Password

What to do

  • Give the work-around more tests
  • Update help doc
    • Add this work-around
    • BTW also mention ConvertFrom-SecureString -AsPlainText in PowerShell 7

Cost

1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions