-
Notifications
You must be signed in to change notification settings - Fork 17
/
azure-az-vmss-snapshot.ps1
94 lines (72 loc) · 2.89 KB
/
azure-az-vmss-snapshot.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<#
.SYNOPSIS
powershell script to update (patch) existing azure arm template resource settings similar to resources.azure.com
.LINK
invoke-webRequest "https://raw.githubusercontent.com/jagilber/powershellScripts/master/azure-az-vmss-snapshot.ps1" -outFile "$pwd\azure-az-vmss-snapshot.ps1";
.\azure-az-vmss-snapshot.ps1 -resourceGroupName {{ resource group name }} -resourceName {{ resource name }}
.DESCRIPTION
powershell script to update (patch) existing azure arm template resource settings similar to resources.azure.com.
.NOTES
File Name : azure-az-vmss-snapshot.ps1
Author : jagilber
Version : 201110
History :
.EXAMPLE
.\azure-az-vmss-snapshot.ps1 -resourceGroupName clusterresourcegroup
#>
[cmdletbinding()]
param (
#[Parameter(Mandatory=$true)]
[string]$resourceGroupName = '',
#[Parameter(Mandatory=$true)]
[string]$location = '',
[string]$vmssName = 'nt0',
[int]$instanceId = 0,
[string]$secretUrl = '',
[string]$vaultResourceId = '',
[string]$keyUrl = '',
[string]$snapshotName = "$resourceGroupName-$vmssName-$instanceId-snapshot-$((get-date).tostring('yyMMddHHmmss'))",
[bool]$encrypt = $false
)
set-strictMode -Version 3.0
$PSModuleAutoLoadingPreference = 2
function main () {
write-host "starting"
write-host "New-AzSnapshotConfig -Location $location `
-DiskSizeGB 100 `
-AccountType Standard_LRS `
-OsType Windows `
-CreateOption Empty `
-EncryptionSettingsEnabled $encrypt" -f green
$snapshotconfig = New-AzSnapshotConfig -Location $location `
-DiskSizeGB 100 `
-AccountType Standard_LRS `
-OsType Windows `
-CreateOption Empty `
-EncryptionSettingsEnabled $encrypt;
if ($encrypt) {
write-host "Set-AzSnapshotDiskEncryptionKey -Snapshot $snapshotconfig `
-SecretUrl $secretUrl `
-SourceVaultId $vaultResourceId" -f green
$snapshotconfig = Set-AzSnapshotDiskEncryptionKey -Snapshot $snapshotconfig `
-SecretUrl $secretUrl `
-SourceVaultId $vaultResourceId;
write-host "Set-AzSnapshotKeyEncryptionKey -Snapshot $snapshotconfig `
-KeyUrl $keyUrl `
-SourceVaultId $vaultResourceId" -f green
$snapshotconfig = Set-AzSnapshotKeyEncryptionKey -Snapshot $snapshotconfig `
-KeyUrl $keyUrl `
-SourceVaultId $vaultResourceId;
}
write-host "New-AzSnapshot -ResourceGroupName $resourceGroupName `
-SnapshotName $snapshotName `
-Snapshot $snapshotconfig" -f green
$global:snapshot = New-AzSnapshot -ResourceGroupName $resourceGroupName `
-SnapshotName $snapshotName `
-Snapshot $snapshotconfig;
$global:snapshot | convertto-json
write-host "Get-AzSnapshot -ResourceGroupName" -f green
Get-AzSnapshot -ResourceGroupName
write-host "results stored in `$global:snapshot" -f cyan
}
main