问题
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
回答1:
Try this:
[string]$VaultName = 'testkeyvault-1'
Get-AzureKeyVaultSecret –VaultName $VaultName |
ForEach-Object {
Backup-AzureKeyVaultSecret `
–VaultName $VaultName `
-Name $_."Name" `
-OutputFile ('C:\Backup_{0}.blob' -f $_."Name")
}
Related documentation:
- Get-AzureKeyVaultSecret
- Backup-AzureKeyVaultSecret
回答2:
You are missing the parameter "Vault Name" inside the LOOP
来源:https://stackoverflow.com/questions/48598673/azure-key-vault-backup-secrets-using-powershell