itsonlyme
itsonlyme

Reputation: 3

Azure cli get Linux Operating system version

Via the Azure cli I can get the Operating system version for Windows machines (using sku), but this does not work for Linux machines. When I look at the Linux VM in the portal it shows "Operating System" "Linux (centos 7.9.2009)" How do I get this detail via CLI? (will accept powershell or resource graph kql also)

I had a browse of resources.azure.com and there does not seem anything obvious to query for. I've also poked around with Powershell Get-AzVM, and Resource graph kusto query.

Here's how i get the info for Windows

az vm list --query '[].{ Name:name, offer:storageProfile.imageReference.offer, publisher:storageProfile.imageReference.publisher, sku:storageProfile.imageReference.sku, version:storageProfile.imageReference.version, os:storageProfile.osDisk.osType}'

sample output of that cmd is

  {
    "Name": "myLinuxServerName",
    "offer": null,
    "os": "Linux",
    "publisher": null,
    "sku": null,
    "version": null
  },
  {
    "Name": "myWindowsServerName",
    "offer": "WindowsServer",
    "os": "Windows",
    "publisher": "MicrosoftWindowsServer",
    "sku": "2019-Datacenter",
    "version": "latest"
  },

here's what i was doing in KQL


resources 
| where type == "microsoft.compute/virtualmachines" and properties.storageProfile.imageReference.offer == "WindowsServer"
| project name,offer=properties.storageProfile.imageReference.offer,sku=properties.storageProfile.imageReference.sku,version=properties.storageProfile.imageReference.version,minorversion=properties.storageProfile.imageReference.exactVersion

Upvotes: 0

Views: 2078

Answers (1)

itsonlyme
itsonlyme

Reputation: 3

I figured it out! There are a couple of other variables that are populated. osName=properties.extended.instanceView.osName

result=centos

osVersion=properties.extended.instanceView.osVersion

result=7.9.2009

My full command is-

resources 
| where type == "microsoft.compute/virtualmachines"
| project name,offer=properties.storageProfile.imageReference.offer,sku=properties.storageProfile.imageReference.sku,publisher=properties.storageProfile.imageReference.publisher,version=properties.storageProfile.imageReference.version,minorversion=properties.storageProfile.imageReference.exactVersion,osName=properties.extended.instanceView.osName,osVersion=properties.extended.instanceView.osVersion
| order by ['name'] asc

The other variables still say "null" for my Linux servers

Upvotes: 0

Related Questions