-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCreate_snapshot.ps1
More file actions
29 lines (21 loc) · 899 Bytes
/
Copy pathCreate_snapshot.ps1
File metadata and controls
29 lines (21 loc) · 899 Bytes
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
Set-Location c:\
Clear-Host
Install-Module -Name Az -Force -AllowClobber -Verbose
#Log into Azure
Connect-AzAccount
#Select the correct subscription
Get-AzSubscription -SubscriptionName "MSDN Platforms" | Select-AzSubscription
#Set some parameters
$resourceGroupName = 'tw-rg01'
$location = 'westeurope'
$vmName = 'tw-winsrv'
$snapshotName = 'mySnapshot'
#Get the VM
$vm = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
#Create the snapshot configuration
$snapshot = New-AzSnapshotConfig -SourceUri $vm.StorageProfile.OsDisk.ManagedDisk.Id -Location $location -CreateOption copy
#Take the snapshot
New-AzSnapshot -Snapshot $snapshot -SnapshotName $snapshotName -ResourceGroupName $resourceGroupName
#Next steps
#Create a virtual machine from a snapshot by creating a managed disk
#from a snapshot and then attaching the new managed disk as the OS disk