Hi Hitesh N
To process all secrets retrieved from Azure Key Vault in a loop - encoding and decoding each one - you can use a foreach loop in PowerShell.
# Retrieve all secrets from the Key Vault
$secrets = Get-AzKeyVaultSecret -VaultName "xxxx"
# Loop through each secret, encode and decode the values
foreach ($secret in $secrets) {
$secretName = $secret.Name
$secretValue = Get-AzKeyVaultSecret -VaultName "xxxx" -Name $secretName -AsPlainText
Write-Host "Original Value for $secretName: $secretValue"
# Encoding
$encodedSecret = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($secretValue))
Write-Host "Encoded Value for $secretName: $encodedSecret"
# Decoding
$decodedValue = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($encodedSecret))
Write-Host "Decoded Value for $secretName: $decodedValue"
}
Hope this helps!
Please Let me know if you have any queries.
If you found the information helpful, please click "Upvote" on the post to let us know and consider accepting the answer as the token of appreciation. Thank You.