-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureRM - Capture VM Image.ps1
58 lines (41 loc) · 1.22 KB
/
AzureRM - Capture VM Image.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
# Authenticate to Azure Account
Login-AzureRmAccount
# Select an Azure subscription
$subscriptionId =
(Get-AzureRmSubscription |
Out-GridView `
-Title "Select an Azure Subscription ..." `
-PassThru).SubscriptionId
Select-AzureRmSubscription `
-SubscriptionId $subscriptionId
# Select existing Resource Group in which VM is contained
$rgName =
(Get-AzureRmResourceGroup).ResourceGroupName |
Out-GridView `
-Title "Select Resource Group in which VM exists ..." `
-PassThru
# Select sysprepp'd VM to capture
$vmName =
(Get-AzureRmVM -ResourceGroup $rgName).Name |
Out-GridView `
-Title "Select VM to Capture Image ..."`
-PassThru
# Capture Azure VM Image
$containerName = "vmimages"
$vhdPrefix = "kemvhd"
Set-AzureRmVM `
-ResourceGroupName $rgName `
-Name $vmName `
-Generalized
$vmTemplate =
Save-AzureRmVMImage `
-ResourceGroupName $rgName `
-Name $vmName `
-DestinationContainerName $containerName `
-VHDNamePrefix $vhdPrefix `
-Overwrite
# Write Captured Template for VM Deployment
$templateFile = ".\vmtemplate.json"
$vmTemplate.Output |
Out-File `
-FilePath $templateFile