skip to Main Content

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

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. Have you tried this? by adding -Status

    Get-AzVM -ResourceGroupName "my-vm-rg" -Name "myvm" -Status | Format-List *
    

    Which also return the OS namd and version
    result:

    ResourceGroupName         : my-vm-rg
    Name                      : myvm
    ComputerName              : myvm
    OsName                    : Windows Server 2022 Datacenter
    OsVersion                 : 10.0.20348.2762
    HyperVGeneration          : V2
    AssignedHost              :
    BootDiagnostics           : Microsoft.Azure.Management.Compute.Models.BootDiagnosticsInstanceView
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search