Created
March 18, 2019 12:38
-
-
Save kevinhillinger/57eaaf4116b80760fa8cca21a40ebc52 to your computer and use it in GitHub Desktop.
Snapshot a VM Scale Set instance and create a managed disk from it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$resourceGroupName = "myResourceGroup" | |
$scalesetName = "myVMScaleSet" | |
$vmInstanceId = 0 | |
$location = "eastus2" | |
$snapshotName = "vmss_snapshot" | |
# create the snapshot | |
$vmss = Get-AzVmssVM -ResourceGroupName $resourceGroupName -VMScaleSetName $scalesetName -InstanceId $vmInstanceId | |
$snapshotConfig = New-AzSnapshotConfig -Location $location -AccountType Standard_LRS -OsType Windows -CreateOption Copy -SourceUri $vmss1.StorageProfile.OsDisk.ManagedDisk.id | |
New-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName -Snapshot $snapshotConfig | |
# create a managed disk from the snapshot | |
$snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName | |
$diskConfig = New-AzDiskConfig -AccountType Premium_LRS -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id | |
$osDisk = New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName ($snapshotName + '_Disk') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment