Share via


OS Version Name Of Azure VMs

Question

Friday, September 14, 2018 7:03 PM

Hi Expert,

I am searching for a way to find any method (Powershell Script) to get all the VM OS name report under subscription. 

 Like we use this command:-

(gwmi win32_operatingsystem).caption

I can find either VM is win or Linux but i am looking for version name either 2012 R2 or 2008 or 2016 etc....

Cheers, Gourav Please remember to mark the replies as answers if it helped.

All replies (14)

Wednesday, September 19, 2018 5:16 AM ✅Answered

You may try the following to get the OS version name of Azure VMs:

Azure PowerShell:

$Pradeep = Get-AzureRmVM

$Pradeep.StorageProfile.ImageReference

Azure CLI:

az vm list --query '[].{ offer:storageProfile.imageReference.offer, publisher:storageProfile.imageReference.publisher, sku:storageProfile.imageReference.sku, version:storageProfile.imageReference.version}'

If this answer was helpful, click “Mark as Answer” or “Up-Vote”. To provide additional feedback on your forum experience, click here


Friday, September 14, 2018 7:34 PM

Please refer to the documentation https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/listall

The OSName and OSVersion properties will return the OS version details.


Friday, September 14, 2018 8:27 PM

How can i run this when i am pasting this command on PS i am getting error, is there anyother method to run this 

GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Compute/virtualMachines?api-version=2017-12-01

Cheers, Gourav Please remember to mark the replies as answers if it helped.


Saturday, September 15, 2018 7:49 AM

To get the OS version name of the Azure VMs, use the below PowerShell cmdlet:

Get-AzureRmVm -ResourceGroupName charlestest | Select-Object -Property StorageProfileText | Format-list

To get it via REST API, you may follow the steps mentioned in the article: “AZURE : “MY FIRST REST API CALL”-TUTORIAL”.

Disclaimer: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

If this answer was helpful, click “Mark as Answer” or “Up-Vote”. To provide additional feedback on your forum experience, click here


Saturday, September 15, 2018 11:48 AM

Hi Pradeep,

When i have executed same command for one of my resource group it has shown me nothing in output. However there are 20 VMs created under this RG.

 

Cheers, Gourav Please remember to mark the replies as answers if it helped.


Tuesday, September 18, 2018 2:52 AM

Hey Gourav,

I’m able to see the output as show above post and also, I’m able to get the output for entire subscription by the following cmdlet:

Get-AzureRmVm | Select-Object -Property StorageProfileText | Format-list

If you are unable to view the output, you may try using different format commands to change output view.

If this answer was helpful, click “Mark as Answer” or “Up-Vote”. To provide additional feedback on your forum experience, click here


Tuesday, September 18, 2018 6:41 AM

Hi Pardeep,

i guess it is a Azure layer error. I tried formatting of table, object, as well sued list , Autosize every command. But no luck!

I thought i need to connect with MS on this.

Cheers, Gourav Please remember to mark the replies as answers if it helped.


Tuesday, September 18, 2018 8:26 AM

Hey Gourav,

I hope you are trying with Azure CloudShell, I would suggest you to try with PowerShell or PowerShell ISE to get the excepted output.


Tuesday, September 18, 2018 9:39 AM

Sir, I tried with PS and PS ISE both. you could see in my screenshot. 

Cheers, Gourav Please remember to mark the replies as answers if it helped.


Tuesday, September 18, 2018 10:20 AM

Hey Gaurav,

I’m able to get the output as mentioned above posts.

You may use the below cmdlet to get complete details about the VM, which contains “Storage Profile”.

Get-AzureRmVM -ResourceGroupName myRG

Since, you are unable to get this info using PowerShell, lets try with REST API.

Using  REST API, click on Try it and select your subscription as shown and click run.

Output:


Tuesday, September 18, 2018 11:38 AM

Let me share my output:-

Get-AzureRmVM -ResourceGroupName XXXXXXX-XXX-RG | select *

I got this outout and in this output we could see there are no Storage Profile attribute.



But when i checked all attributes for this command. I could see storageprofile so i tried below command

 Get-AzureRmVM -ResourceGroupName XXXXXX-XXXX-XXXX-RG | select StorageProfile, Name

But i am getting this :-

Its all mess here. Do not know what is happening some command are running and some are not.....

output is mess....

Cheers, Gourav Please remember to mark the replies as answers if it helped.


Wednesday, September 19, 2018 5:32 AM

Awesome :)

This is working fine. Really appreciate your time and efforts here

Cheers, Gourav Please remember to mark the replies as answers if it helped.


Wednesday, September 19, 2018 5:39 AM

Glad to know it helped.


Tuesday, October 9, 2018 6:37 AM

Sorry, I have not checked this fully. There is no VM name in given query.

$Pradeep = Get-AzureRmVM

$Pradeep.StorageProfile.ImageReference

Cheers, Gourav Please remember to mark the replies as answers if it helped.