azureazure-powershellazure-virtual-machine

Get the Operating system details of the in-place upgraded Azure VM using Azure PowerShell


I am using below script to create report of the hosts with Operating system. I noticed some of the VMs have Source Image Offer different than Operating system as those were upgraded in-place.

Is there way to fetch this information from Azure PowerShell?

$vm = Get-AzVM -ResourceGroupName my-rg -Name myhostname1
$offer = $vm.StorageProfile.ImageReference.Offer  # Windows-10
$sku = $vm.StorageProfile.ImageReference.Sku      # win10-22h2-ent-g2

Expected outcome is: Windows (Windows 11 Enterprise).

enter image description here


Solution

  • Get the Operating system details of the in-place upgraded Azure VM using Azure PowerShell

    In your case, the Source Image Offer is different from the Operating system. You can find the correct Operating System information using the command below.

    $VMinfo= Invoke-AzVMRunCommand -ResourceGroupName 'networktest-vnet' -VMName 'Venkat-vm' -CommandId 'RunPowerShellScript' -ScriptString "Systeminfo"
    

    This will fetch the VM OS information available in Systeminfo, not from the azure portal, allowing you to find the correct information.

    enter image description here

    Here is the Azure PowerShell command to fetch the VM Source Image Offer details which are available in azure portal.

    $vm = Get-AzVM -ResourceGroupName "networktest-vnet" -Name "Venkat-vm"
    $vmName = $vm.Name
    $osType = $vm.StorageProfile.OsDisk.OsType
    $imageReference = $vm.StorageProfile.ImageReference