/
kvextensionWin.ps1
45 lines (39 loc) · 1.73 KB
/
kvextensionWin.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# NOTE
# Remeber to assign to the system managed identity of the VM the "Key Vault Secret User" role on the Key Vault
# Customizable variables
$vmName = "win01" # Name of the VM where the extension will be deployed
$VMresourceGroupName = "certlc" # Resource group where the VM is located
$location = "westeurope" # Location of the VM
$keyVaultName = "DEMO-KV-fab01" # Name of the Key Vault holding the certificate
$certifcateName = "democert" # Name of the certificate in the Key Vault
$pollingInterval = "43200" # Polling interval in seconds (e.g. 43200 = 12 hours)
# Build settings on Windows VM
$Settings = @'
{
"secretsManagementSettings": {
"pollingIntervalInS": "POLLINGPLACEHOLDER",
"linkOnRenewal": false,
"observedCertificates":
[
{
"url": "https://KVPLACEHOLDER.vault.azure.net:443/secrets/CERTPLACEHOLDER",
"certificateStoreName": "MY",
"certificateStoreLocation": "LocalMachine",
"keyExportable": true,
"accounts": [
"Network Service",
"Local Service"
]
}
]
}
}
'@
$Settings = $Settings.Replace("POLLINGPLACEHOLDER",$pollingInterval)
$Settings = $Settings.Replace("KVPLACEHOLDER",$keyVaultName)
$Settings = $Settings.Replace("CERTPLACEHOLDER",$certifcateName)
$extName = "KeyVaultForWindows"
$extPublisher = "Microsoft.Azure.KeyVault"
$extType = "KeyVaultForWindows"
# Start the deployment on Windows VM
Set-AzVmExtension -TypeHandlerVersion "3.0" -ResourceGroupName $VMresourceGroupName -Location $location -VMName $vmName -Name $extName -Publisher $extPublisher -Type $extType -SettingString $settings