how to find all guest OS version in azure vms by command shell?

Mujeeb Alvi 21 Reputation points
2022-01-11T04:26:49.373+00:00

want to know the script to find all guest OS versions in one subscription

Microsoft Purview
Microsoft Purview
A Microsoft data governance service that helps manage and govern on-premises, multicloud, and software-as-a-service data. Previously known as Azure Purview.
1,388 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sreeju Nair 12,611 Reputation points
    2022-01-11T05:45:37.42+00:00

    Try the following command.

    $vm = Get-AzVM -VMName <VmName>
    $vm.StorageProfile.ImageReference
    

    This will give you some more details as below example

    Publisher : MicrosoftWindowsServer
    Offer : WindowsServer
    Sku : 2016-Datacenter
    Version : latest
    ExactVersion : 14393.4225.2102030345

    Hope this helps

    2 people found this answer helpful.

4 additional answers

Sort by: Most helpful
  1. Sreeju Nair 12,611 Reputation points
    2022-01-11T04:54:14.767+00:00

    To get the OS details in an Azure VM, you can use the following command in powershell.

    Get-AzureRmVM -ResourceGroupName TEST -Name VMNAME |
    Format-Table Name, @{l='osType';e={$_.StorageProfile.osDisk.osType}}

    This will produce the following output

    Name osType


    VMNAME Windows

    1 person found this answer helpful.
    0 comments No comments

  2. TL 5 Reputation points
    2024-01-15T11:55:21.5533333+00:00

    Important to note that this will only work if the VM was built using an image from the Azure marketplace. If the VM has been migrated from on-premises or the OS was installed in some other manner, the StorageProfile.ImageReference property is empty. https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.management.compute.models.storageprofile.imagereference?view=azure-dotnet-legacy

    1 person found this answer helpful.
    0 comments No comments

  3. Mujeeb Alvi 21 Reputation points
    2022-01-11T05:38:33.513+00:00

    Thanks for your help but it gives only os type like windows/linux and i want the os version name like 2012r2, 2016

    0 comments No comments

  4. Mujeeb Alvi 21 Reputation points
    2022-01-11T06:00:34.21+00:00

    thanks for the info it works

    Publisher : MicrosoftWindowsServer
    Offer : WindowsServer
    Sku : 2012-R2-Datacenter
    Version : latest
    ExactVersion : 9600.19542.19111201

    0 comments No comments

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.