Azure / Azure/azure-powershell
Should be a slick way to store and retrieve a PSCredential object from a Key Vault Secret
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 54
Description
## Description of the new feature
Need an easy way to store and retrieve a PSCredential object. For example:
$creds = Get-Credential
Set-AzKeyVaultSecret -VaultName $vaultName -name $secretName -PsCredential $creds
and
$credsRetrieved = Get-AzKeyVaultSecret -vaultName $VaultName -name $secretName -PsCredential
## The Existing Mechanism
Here is the clunky way I have come up with to do it:
$Creds = Get-Credential -Message "$msg"
# create an vertical tab-delimited string from the values entered
$secretstring = $Creds.GetNetworkCredential().UserName + "`v" + $Creds.GetNetworkCredential().Password
$secretvalue = ConvertTo-SecureString $secretstring -AsPlainText -Force
# store in Key Vault
Set-AzKeyVaultSecret -VaultName $VaultName -name $DomainSecretName -secretvalue $secretvalue
and
$secretValueParts = (Get-AzKeyVaultSecret -vaultName $VaultName -name $DomainSecretName).SecretValueText -Split "``v"
$password = ConvertTo-SecureString $secretValueParts[1] -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($secretValueParts[0], $password)
Contributor guide
Assessment
This issue has not been assessed yet.