

$dataDisks = ($snapshotdisk.DataDisks).name Write-Output "VM $($vm.name) Data Disk Snapshots Begin" Write-Output "VM $($vm.name) OS Disk Snapshot End" New-AzSnapshot -ResourceGroupName $VmResourceGroup -SnapshotName $snapshotNameOS -Snapshot $OSDiskSnapshotConfig -ErrorAction Stop $snapshotNameOS = "$($)_snapshot_$(Get-Date -Format ddMMyy)" $OSDiskSnapshotConfig = New-AzSnapshotConfig -SourceUri $ -CreateOption Copy -Location eastus -OsType Windows

Write-Output "VM $($vm.name) OS Disk Snapshot Begin" $vm = get-azvm -Name $VmName -ResourceGroupName $VmResourceGroup VM tamops-vm data Disk datadisk2 Snapshot End Id : /subscriptions/xxxx-xxx-xxxxxxxxx/resourceGroups/tamops-snapshots/providers/Microsoft.Compute/snapshots/datadisk2_s VM tamops-vm data Disk datadisk2 Snapshot Begin VM tamops-vm data Disk datadisk1 Snapshot End Id : /subscriptions/xxxx-xxx-xxxxxxxxx/resourceGroups/tamops-snapshots/providers/Microsoft.Compute/snapshots/datadisk1_s Sku : .Models.SnapshotSkuĬreationData : .Models.CreationData if ($CopyStatus.VM tamops-vm data Disk datadisk1 Snapshot Begin If you have mixed resources in a resourcegroup DO NOT RUN this. Note: This will delete all resources in the resource group. When the upload completes it is time to clean up the remaining resources. This is what it looks like in the storage account:

It takes about 15 – 20 minutes for the upload to complete. This “do while” loop checks the upload status every 60 seconds and reports back whether the upload has finished. If ($installedPackageProvider.Name -notmatch "NuGet") while ($CopyStatus.Status -eq "Pending") Use this code to do so: $installedPackageProvider = Get-PackageProvider This is the VM we are capturing:įirstly, we need to install the modules needed to use the CMDlets. In this section of the blog we are going to capture the image and removed the VM’s resources. You have a VM and this VM runs on managed disks.Ĭreate a storage account which has a container called, for example, images. (The complete script is available at the bottom of the page) Prerequisites We are going to snapshot the managed disk of the machine and upload it to a Storage Account.įor example, you can use this blog/script to create an image for Citrix Cloud. This is a blogpost about creating an image from an existing Virtual Machine on Microsoft Azure. Azure, Image, ManagedDisk, ManagedImage, StorageAccount, WindowsVirtualDesktop, WVD
