Instantly share code, notes, and snippets.

Embed
What would you like to do?
## Log in to Azure Resource Manager
Add-AzureRmAccount
## Create Resource Group
$resourceGroupName = 'keyvault'
$location = 'Australia Southeast'
$resourceGroup = New-AzureRmResourceGroup `
-Name $resourceGroupName `
-Location $location -Force
$resourceGroup
## Create Azure KeyVault
Function Get-StringHash([String] $String,$HashName = "MD5")
{
$StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{
[Void]$StringBuilder.Append($_.ToString("x2"))
}
$StringBuilder.ToString()
}
$vaultName = 'myVault'
$uniqueString = (Get-StringHash -String $resourceGroup.ResourceId).substring(0,10)
$vaultName = $vaultName + $uniqueString
$vault = New-AzureRmKeyVault `
-VaultName $vaultName `
-ResourceGroupName $resourceGroup.ResourceGroupName `
-Location $resourceGroup.Location `
-EnabledForTemplateDeployment -Verbose
$vault
## Get Certificate details
$certPath = "$env:USERPROFILE\Documents\git\chef-hosted\.chef"
$certName = 'chef-org-validator.pem'
$cert = $certPath + '\' + $certName
$secretName = 'chef-org-validator'
$secretValue = Get-Content $cert -Raw | ConvertTo-SecureString -AsPlainText -Force
## Create Key Vault secret
$vaultSecret = Set-AzureKeyVaultSecret `
-VaultName $vault.VaultName `
-Name $secretName `
-SecretValue $secretValue `
-Verbose
$vaultSecret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment