Share via


How to get Azure VM operating sytsem version with Powershell?

Question

Monday, April 15, 2019 12:48 PM

I have built some Azure VM inventory scripts with the Az and RM Powershell modules.  Originally recorded the "operating system" as either "Windows" or "Linux" but now I want to enhance to get the actual OS version as we do run different flavors (ie Windows 2012 R2 and Windows 2016).

I am using Get-AzResource to get the VM information, and then taking the $_.Properties.storageProfile.osDisk.osType property of each VM.  This results in a value of either "Windows" or "Linux" but no other information such as build/version of said OS.  Looking at the VM's from the Azure web portal, I also only see the "operating system" generically tagged as "Windows" or "Linux", but again no version/build.

I know I can retrieve the operating system versions, by querying the servers directly, or perhaps even querying Active Directory within the same inventory script.  But to limit script requirements/dependencies/network restrictions etc. it would be ideal to obtain the information from the Az module.  Can anyone point me in the right direction, or confirm if it can't be done?

Thanks.

All replies (3)

Monday, April 15, 2019 2:09 PM

You would need to retrieve the image reference

Details at https://community.spiceworks.com/topic/2073475-how-to-get-the-azure-virtual-machine-operating-system-details

hth
Marcin


Monday, April 15, 2019 2:39 PM

Marcin,

Thanks for the tip - all I had to do was record a property I'm already querying for:

$_.Properties.StorageProfile.ImageReference

But the issue is the image names are arbitrary.  Most of ours names do contain the OS version, but it's not required.  We have some for example that say "Database_for_AppX".  I know myself it's a RHEL image but it's not telling of the specific OS version.

Is there a way to directly get the OS - or is this the best option while sticking within the Az/RM modules? 


Monday, April 15, 2019 3:22 PM

Not without opening ports through which you'll be able to connect (SSH or WinRM) - unless you run your script from CloudShell, which facilitates direct connectivity to the OS, allowing you to query it directly (obviously at that point you will no longer be relying on Az PowerShell

hth
Marcin