Yes the keyvault already exists, I am fairly new to powershell so am quite stuck after the commands above it displays the primary key but not sure what powershell command to use to use that primary key and store it as a secret in a keyvault…
$ResourceGroupName = "test"
# We retrieve the key from the 'test01cache' Redis cache, and store it in a variable ('CacheKey')
$CacheKey = Get-AzRedisCacheKey -ResourceGroupName $ResourceGroupName -Name "test01cache"
# We find the KeyVault in the resource group (assuming there's only one)
$KeyVault = Get-AzKeyVault -ResourceGroupName $ResourceGroupName
# Set-AzKeyVaultSecret accepts SecureString, not string, so we probably need to convert the key
$SecureCacheKey = ConvertTo-SecureString -String $CacheKey -AsPlainText -Force
# We can then store $SecureCacheKey in the KeyVault we found
Set-AzKeyVaultSecret -VaultName $KeyVault.VaultName -Name "RedisCacheKey" -SecretValue $SecureCacheKey
Ah, apologies. This is where I regret not testing the code / having a Redis Cache to test against.
It seems likely that there will be a property on that object that we need to specify, instead of using the default ToString method. Can you, excluding any potentially sensitive information, show the output of either:
$CacheKey
# ...or...
$CacheKey | Get-Member
Edit: A quick Google shows that it should have two properties - PrimaryKey and SecondaryKey.
If you adjust the code above to `ConvertTo-SecureString $CacheKey.PrimaryKey […]`, that should solve it.
[quote quote=177640]Ah, apologies. This is where I regret not testing the code / having a Redis Cache to test against.
It seems likely that there will be a property on that object that we need to specify, instead of using the default ToString method. Can you, excluding any potentially sensitive information, show the output of either: