The days change, but sometimes the issues stay the same. This is a redux of an existing post where there was an issue back in 2016 when I was not able to easily re-create a VM in a different Availability Set. As you can see in Create Azure RM VM Using Existing VHD – 250 Hello (rmilne.ca) PowerShell was used to re-create the VM as it allowed all of the resources to be specified.
The original VM was first documented to ensure that the path to the VHD, network configuration etc. was all captured.
The VM was then deleted. This freed up the VHD to be used in a different machine.
Note in the screenshot below, the highlighted VHD has a Lease State of "Available". This is highlighted.
Also of note is that there is no UI option to create a VM from this disk. This is an older VM, as you can tell as it has a date of 2015 in its name, and it is NOT a managed disk. The type is unmanaged, as this environment has not been migrated to managed disks (yet).
Since the older Azure RM cmdlets are outdated, the original script was updated. Please also see Migrate Azure PowerShell from AzureRM to Az as changes will be required to other scripts that you may have with the older cmdlets.
Please read the original post for the associated steps and notes.
The script can be downloaded from GitHub:
The intent is that you log onto to Azure, obtain the necessary information to add into the script then run the script interactively in you local PowerShell session to recreate the VM.
As noted above, ensure that you have the Az module installed. If not, install the new Azure module:
Install-Module -Name AZ –Force |
Once you have the module installed, updated the sample script you should be able to re-create the VM from the unmanaged disk.
Cheers,
Rhoderick