Skip to content

Instantly share code, notes, and snippets.

@jamesbannan
Created March 2, 2017 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesbannan/defea5e2e2eac00490519e2029e10385 to your computer and use it in GitHub Desktop.
Save jamesbannan/defea5e2e2eac00490519e2029e10385 to your computer and use it in GitHub Desktop.
## 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