Azure Key Vault: Backup Secrets using PowerShell

戏子无情 提交于 2020-01-25 06:49:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!