Convert Azure VMs to Managed Disks using PowerShell
·581 words·3 mins·100 views·5 likes·
Azure PowerShell Connect-AzAccount ConvertTo-AzVMManagedDisk Get-AzAvailabilitySet Get-AzSubscription Get-AzVM Microsoft Microsoft Azure Select-AzSubscription Stop-AzVM Storage Update-AzAvailabilitySet Virtual machines
This post will show you how to convert a virtual machine, whether within an availability group or a single instance, from unmanaged disks (Storage Account) to disks managed using Azure PowerShell. Requirements: This tutorial assumes that you already have a Microsoft Azure account set up. Important: Before starting the conversion process, you should keep in mind the following.
The conversion requires a restart of the VM
The conversion is not reversible.
The virtual machine will receive a new IP address after the conversion if it uses dynamic IP.
The VHDs and the storage account used by the VM before conversion are not deleted.
If you want to know how to install the PowerShell Azure module on your machine, check out this
link. The simplest way to get started is to sign in interactively at the command line.
Connect-AzAccount
This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account. If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:
Convert the availability set to a managed availability set>
Convert the availability set to a managed availability set
#
Before converting virtual machines, you must first convert the availability set to a managed availability set. To do this, use the Update-AzAvailabilitySet cmdlet with the following syntax:
Deallocate and convert the VMs in the availability set>
Deallocate and convert the VMs in the availability set
#
With the following script, we go through all the virtual machines within the availability group. First, we deallocate them with the Stop-AZM cmdlet and then convert them with the ConvertTo-AzVMManagedDisk cmdlet.