-
Notifications
You must be signed in to change notification settings - Fork 0
/
Machine-snapshot.ps1
41 lines (23 loc) · 960 Bytes
/
Machine-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
#https://arlanblogs.alvarnet.com/create-an-azure-disk-snapshot-posh/
#Assumed Logged into AZ
## Login-AzAccount
## Get-AzSubscription
## Select-AzSubscription "XXX""
##TBC
#Tagging
function Take-Snapshot {
param (
[Parameter(Mandatory = $True)] [string] $vmname
)
$name = "DC1"
$date = Get-Date -Format yyyy-MM-dd-%H-mm
$vm = get-azvm -name $name | select Location, Name, ResourceGroupName, storageprofile
#OS Type
#$vm.StorageProfile.OsDisk.OsType
# $vm.StorageProfile.OsDisk.name
$OSDisk = Get-AzDisk -DiskName $vm.StorageProfile.OsDisk.name -ResourceGroupName $vm.ResourceGroupName
$OSSnapshotConfig = New-AzSnapshotConfig -SourceUri $OSDisk.Id -CreateOption Copy -Location $vm.Location
$Snapshot = New-AzSnapshot -Snapshot $OSSnapshotConfig -SnapshotName ($date + '_OSDisk_ViaScript') -ResourceGroupName $vm.ResourceGroupName
#datadisks
#$vm.StorageProfile.DataDisks.name
}