Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinhillinger/57eaaf4116b80760fa8cca21a40ebc52 to your computer and use it in GitHub Desktop.
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
$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