
Using AzCopy, send the snapshot to the container1 within the storage account provisioned with this lab. Create an Azure Storage context: $destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey. Once the VM has stopped, grant access to the disk: $sas = Grant-AzDiskAccess -ResourceGroupName $rg -DiskName $diskName -DurationInSecond $sasExpiryDuration -Access Read. Use the appropriate commands to take a snapshot of the VM. Stop the VM: Stop-AzVM -ResourceGroupName $rg -Name $vmName. Create additional variables: $storageContainerName = "container1". In the Azure Portal, copy the storage account key for key1, and create a new variable: $storageAccountKey = "". In the Azure Portal, copy the storage account name, and create a new variable: $storageAccountName = "". Create a variable for sasExpiryDuration: $sasExpiryDuration = "3600". In the Azure Portal, copy the name of the VM disk and create a new variable: $diskname = "". In the Cloud Shell, create a new variable: $rg = "". In the Azure Portal, click All resources and copy the name of the pre-provisioned resource group. Use the correct PowerShell command to stop and deallocate the VM that’s provisioned with this lab. if ($CopyStatus.Successfully complete this lab by achieving the following learning objectives: Stop the Virtual Machine 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