Home > Net >  How to add multiple keys to Azure key vault?
How to add multiple keys to Azure key vault?

Time:10-07

I want to add around 50 keys and have thought of two approches-

  1. by adding keys to the template of key vault or
  2. using add command in powershell to add keys one by one but it is too time consuming and repetitive, so is there a way to add these keys in simpler way?

ps- I do not want to create keys using azure portal.

CodePudding user response:

We have tested in our local environment, By creating the 50 keys in a csv file & tried adding them to key vault by using the below PowerShell script . It took around 3 minutes 06 seconds to complete script & to create 50 keys in key vault.

Here is the PowerShell script :

 $Expires = (Get-Date).AddYears(2).ToUniversalTime()
$NotBefore = (Get-Date).ToUniversalTime()

Import-Csv C:\Users\Downloads\keys.csv|foreach{

Add-AzKeyVaultKey -VaultName '<keyvaultName>' -Name $_.Name -Destination 'Software' -Expires $Expires -NotBefore $NotBefore

}

Here is the screen shot for reference :

enter image description here

Here is reference Azure documentation for add-azkeyvaultkey cmdlet to create a key using different parameters based on the requirement.

  • Related