Export VM disk mapping - addycluri/Azure GitHub Wiki

This wiki should help export a report of VM(s) along with the disks attached to it. Important Properties like VMName, VM ResourceGroup, Disk name, Disktype, Disk URI, ETC ar captured and exported to a CSV to help understand the VM-storage map for your infrastructure.

Apart from on-demand reporting capabilities and general validations, such a report can be primarily helpful when migraating Azure resources using the resource move feature. Please see the next section where this is described.

Sample Report

VMNAME VM-RG DISK-NAME DISK-PURPOSE DISK-TYPE VHD-URI DISK-RG DISK-SIZE(GB)
VM1 ResourceGroup-A 14065k8s9000-osdisk OS DISK UN-MANAGED https://path/osdisk/blob.vhd ResourceGroup-A 30
VM2 ResourceGroup-B 14065k8s9001-osdisk OS DISK UN-MANAGED https://path/osdisk/blob.vhd ResourceGroup-B 30
VM3 ResourceGroup-C 14065k8s9002-osdisk OS DISK MANAGED path/Microsoft.Compute/disks/14065K8s9002-osdisk ResourceGroup-C 30
VM3 ResourceGroup-C 14065k8s9002-data DATA DISK MANAGED path/Microsoft.Compute/disks/14065K8s9002-data ResourceGroup-D 60

We can see here that VM3 is hosted in ResourceGroup-C while its data disks is in a different one - ResourceGroup-D. Now, If you try to move the VM the validation will fail complaining about a dependent resource (data disk) not present in the same resource group. It is a requirement that all dependent resources (EX: NIC, disks, ETC.) must be in the same resource or the data disk has to be detached from the VM and moved separately causing downtime.

Now you should be in a better position and take corrective actions to move the disks to the same resource group as the VM and unblock your migration.

Execution Steps

  • Download and import the Powershell Module locally using the instructions provided - here

  • Open PowerShell and run Get-Help Get-VMDiskMapping -Full to get an understanding of how the function works and the input parameters required.

  • Login to your source azure account using Connect-AzureRmAccount -TenantId "GUID" -SubscriptionId "GUID" (where the VMs with managed disks currently live)

  • CD to location where you want the report to be saved (or the report will be saved to whichever location you are currently in)

  • Run the command - Get-VMDiskMapping -RGName "MY-RG"

⚠️ **GitHub.com Fallback** ⚠️