VCPUS for Windows Server 2012 VMs

Ram Kumar Cheekoti 141 Reputation points
2023-11-28T04:25:17.1466667+00:00

Hi Team,

Need help on how to get the number of cores for each VM and the total number of cores for all Windows Server 2012 R2 VMs ,

We can filter by OS Type by using az vm list sizes command but not based on the type of windows (SKU) type. Can you please help me to get the same

az vm list-sizes -l canadacentral --os-type  --> this only gives windows server but not windws server 2012 and should be extracted to csv/xlsx

Thank you!

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,562 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,600 questions
{count} votes

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 19,641 Reputation points Microsoft Employee
    2023-11-28T10:50:19.8533333+00:00

    @Ram Kumar Cheekoti Thanks for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this.

    You can use the PowerShell script to pull the list of all Windows Server 2012 R2 in the subscription with their respective SKU and total number of SKU of the VM's.

    Here is the PowerShell Script:

    $vmlist= Get-AzVM | select -Property Name,ResourceGroupName
    $count=0
    $output= @()
    
    foreach( $item in $vmlist){
        
        $Imagesku= (Get-AzVM -Name $item.Name).StorageProfile.ImageReference.Sku
        
        if( $Imagesku -match "2019"){
    
           $hdsize=(Get-AzVM -Name $item.Name).HardwareProfile.VmSize
    
            $cores=(Get-AzVMSize -VMName $item.Name -ResourceGroupName $item.ResourceGroupName | where {$_.Name -eq $hdsize}).NumberOfCores
            $count+=$cores
            $output += [PSCustomObject]@{
                VMName = $item.Name
                Cores = $cores
                VMSize = $hdsize
        
        }
        }
    
    }
    
    $output += [PSCustomObject]@{
        VMName = "Total"
        Cores = $count
        VMSize = $hdsize
    }
    
    $output | Export-Csv -Path "C:\output.csv" -NoTypeInformation
    

    Here is the sample output for your reference:

    User's image

    Note: Please change the above PowerShell script based on your requirements. In the above PowerShell script we have pulled the list for VM's which are running 2019 windows servers.

    Feel free to reach back to me if you have any further questions on this.

    0 comments No comments