简体   繁体   中英

Azure Key Vault: Backup Secrets using PowerShell

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

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:

您在 LOOP 中缺少参数“Vault Name”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM