Need to export VM details along with data disk details

Vinoth Kaliaperumal 386 Reputation points
2023-07-27T03:44:48.4266667+00:00

Hi Team,

I need to export the Azure VM list along with the details of data disks attached with their sizes.

Is it possible to get via GUI or need to use resource graph explorer.

Thanks.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,056 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
650 questions
0 comments No comments
{count} votes

Accepted answer
  1. Manu Philip 18,691 Reputation points MVP
    2023-07-27T05:33:45.9866667+00:00

    If you are looking for a different solution based on AZ CLI, you may use the following PowerShell script.

    $report = @()
        $vms = Get-AzVM
        foreach ($vm in $vms) { 
            $info = "" | Select VmName, ResourceGroupName, Region, VmSize, OsType, Cores, Memory, OSDiskSize, DataDisksSizeinGB
                [string]$sku = $vm.StorageProfile.ImageReference.Sku
                [string]$os = $vm.StorageProfile.ImageReference.Offer
                $osDiskName = $vm.StorageProfile.OsDisk.Name
                $info.VMName = $vm.Name
    			$vmLocation = $vm.location 			
                $info.OsType = $os + " " + $sku
                $info.ResourceGroupName = $vm.ResourceGroupName
                $info.VmSize = $vm.HardwareProfile.VmSize
                $sizeDetails = Get-AzVMSize -Location $vmLocation | where {$_.Name -eq $vm.HardwareProfile.VmSize}
                $info.Cores = $sizeDetails.NumberOfCores
                $info.Memory = $sizeDetails.MemoryInMB
    			$disk = Get-AzDisk -DiskName $osDiskName -ResourceGroupName $vm.ResourceGroupName
    			$info.OSDiskSize = $disk.DiskSizeGB
                if ($vm.StorageProfile.DataDisks.Count -gt 0) {
                    $disksum = $vm.StorageProfile.dataDisks.diskSizeGB | foreach { $_ }
                $info.DataDisksSizeinGB = $disksum
                }
                
                $report+=$info
                }
    $report | ft VmName, ResourceGroupName, Region, VmSize, OsType, Cores, Memory, OSDiskSize, DataDisksSizeinGB
    
    

    You will get similar details as below for the VMs

    User's image


    --please don't forget to upvote and Accept as answer if the reply is helpful--

    3 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Ramya Harinarthini_MSFT 5,356 Reputation points Microsoft Employee
    2023-07-27T04:52:41.3733333+00:00

    vinothkaliaperumal-2643 Welcome to Microsoft Q&A, Thank you for posting your here!!

    Azure portal doesn't have built-in feature to export the list of Azure Virtual Machines (VMs) along with the details of their attached data disks and sizes directly through the GUI.

    Resource Graph Explorer in the Azure portal allows you to query and explore Azure resources but does not directly support exporting VM details along with their attached data disks.You can separately export the list of all the VMs from VM blade and managed disks from Disks blade

    You can use Azure Resource Graph to query your resources in Azure, the results of which can then be exported in CSV format. You can run this directly in the portal using Azure Resource Graph Explorer. The following query will get you the VM size, VM name, Subscription name.

    Resources
    | where type =~ 'Microsoft.Compute/virtualMachines'
    | join kind=leftouter (ResourceContainers | where type=='microsoft.resources/subscriptions' | project SubName=name, subscriptionId) on subscriptionId
    | project name, properties.hardwareProfile.vmSize, SubName
    | order by name desc
    

    Hope this helps! Kindly let us know if the above helps or you need further assistance on this issue.


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.