I am trying to run the following PS script to back-up all of the Secrets, in a specific Azure Key Vault:
$secret = Get-AzureKeyVaultSecret –VaultName 'testkeyvault-1' |
ForEach-Object {
$Name = $_."Name"
Backup-AzureKeyVaultSecret -Secret $Name -OutputFile 'C:\Backup.blob'
}
Though this is failing with the following PS error, any help would be appreciated:
Backup-AzureKeyVaultSecret : Cannot bind parameter 'Secret'. Cannot convert the "SQLSecret" value of type "System.String" to type "Microsoft.Azure.Commands.KeyVault.Models.Secret".
At line:4 char:36
+ Backup-AzureKeyVaultSecret -Secret $Name -OutputFile 'C:\Backup.blob'
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Backup- AzureKeyVaultSecret], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.KeyVault.BackupAzureKeyVaultSecret
-Secret $_
instead of assigning only the name value. (Not familiar with this function, so not sure if this will work; but the error implies this is likely the issue). – JohnLBevan$_."Name"
would also be returning null (since in PS the property of a null object is itself null)... so I'd have though you should have received the same error when using$Name
previously... unless this isn't the first item in the list. – JohnLBevanForEach-Object {
toWhere-Object {$_} | ForEach-Object {
. i.e. that should filter out any null values in the list. Od that any would be returned; but maybe that will help. Beyond that; don't think I can come up with any other good suggestions I'm afraid... – JohnLBevanBackup-AzureKeyVaultSecret : Cannot bind parameter 'Secret'. Cannot convert the "TestUsername" value of type "System.String" to type "Microsoft.Azure.Commands.KeyVault.Models.Secret". At line:4 char:36 + Backup-AzureKeyVaultSecret -Secret $_."Name" -OutputFile 'C:\Backup.b ...
– Fuzzy Logic