export azure resources with sku and configuration

ares 201 Reputation points
2023-01-26T10:43:26.7366667+00:00

Hi all

I need to create an export of all resources configured in my subscription, with all the info like vm type and configuration, in order to let me do a cost estimate with the azure calculator. As I have found until now, i can do export but i miss all the info like vm d2sv4 disk size etc, how can i have a complete export of all resources?

thanks

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,130 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Manu Philip 16,971 Reputation points MVP
    2023-01-26T14:46:31.1266667+00:00

    Following PowerShell script can be used to get the details you are looking for

    $report = @()
    $subs = Get-AzSubscription
    Foreach ($sub in $subs)
        {
        select-AzSubscription $sub | Out-Null
        $subName = $sub.Name
    
        $vms = Get-AzVM
        foreach ($vm in $vms) { 
            $info = "" | Select VmName, ResourceGroupName, Region, VmSize, OsType, Subscription, Cores, Memory, OSDiskSize
                [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
                $info.Subscription = $subName
                $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
                $report+=$info
                } 
        }
    $report | ft VmName, ResourceGroupName, Region, VmSize, OsType, Subscription, Cores, Memory, OSDiskSize
    

    PowerShell Output should be like as below:

    User's image

    -

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

    0 comments No comments