5

I'm trying to use the Azure Powershell 7 commandlet to get the latest version of the Canonical UbuntuServer 18.04-LTS.

Here is an example of my query:

>> Get-AzVMImage -Location "eastus" -PublisherName "Canonical" -Offer "UbuntuServer" -Skus "18.04-LTS" -Version "latest"

After authenticating, I try to run that commandlet, and I get the following error:

Get-AzVMImage:
Line |
   2 |  Get-AzVMImage -Location "eastus" -PublisherName "Canonical" -Offer "U …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The value of parameter version is invalid.
ErrorCode: InvalidParameter
ErrorMessage: The value of parameter version is invalid.
ErrorTarget: version
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 3cf54862-47c7-4092-97e9-20ae6556f37c

However, if I hard-code the -Version flag to a known version number, like so:

>> Get-AzVMImage -Location "eastus" -PublisherName "Canonical" -Offer "UbuntuServer" -Skus "18.04-LTS" -Version "18.04.202109280"

I receive a successful response:

Location         : eastus
PublisherName    : Canonical
Offer            : UbuntuServer
Skus             : 18.04-LTS
Version          : 18.04.202109280
FilterExpression :
Name             : 18.04.202109280
HyperVGeneration : V1
OSDiskImage      : {
                     "operatingSystem": "Linux"
                   }
PurchasePlan     : null
DataDiskImages   : []

This Azure article on how find and use marketplace images Find and use Azure Marketplace VM images with Azure PowerShell states " ... For a SKU, list the versions of the image using Get-AzVMImage. You can also use latest if you want to use the latest image and not a specific older version."

As an alternative, it also mentions you can use the URN format instead "... These values can be passed individually or as an image URN, combining the values separated by the colon (:). For example: Publisher:Offer:Sku:Version. You can replace the version number in the URN with latest to use the latest version of the image."

Does anyone know what I need to change in order to just use -Version "latest"?

I've considering querying for all the versions first and getting the last one in the list. Then, I would set a $version variable to last version number. But that seems to run counter to what is suggested in the Azure documentation.

darlirium
  • 51
  • 4
  • 1
    We have tested in our local environment, we tried pulling the ``latest`` version image of ubuntu server 18.04-lts using `get-azvmimage` cmdlet by passing the `version` value as ``latest`` or urn value ``Canonical:UbuntuServer:18.04-LTS:latest`` as suggested in the [documentation](https://learn.microsoft.com/en-us/azure/virtual-machines/windows/cli-ps-findimage#terminology) even it is failing irrespective of the PowerShell version either in 5.1 or 7 – VenkateshDodda Oct 14 '21 at 08:46
  • 1
    Alternatively , you can use the below azure cli cmdlet to pull the latest image version of the ubuntu server 18.04-lts using urn parameter as shown in this [image](https://imgur.com/R0Ru46a). az vm image show --location westus --urn Canonical:UbuntuServer:18.04-LTS:latest (or) Get-AzVMImage -Location eastus -PublisherName Canonical -Offer UbuntuServer -Skus 18.04-LTS | Select-Object version -Last 1 – VenkateshDodda Oct 14 '21 at 08:46
  • @VenkateshDodda-MT Thanks for confirming in your local environment. I only tried testing getting the `latest` version of `UbuntuServer:18.04-LTS`. My guess is that it also fails for other SKUs be cannot be sure without testing it. And, yes, you are correct if I run the `az vm image show --location westus --urn Canonical:UbuntuServer:18.04-LTS:latest` I do receive a successful Azure response with that image data. – darlirium Oct 14 '21 at 17:57
  • [Get-AzVMImageSku](https://learn.microsoft.com/en-us/powershell/module/Az.Compute/get-azvmimagesku?view=azps-9.3.0&viewFallbackFrom=azps-9.1.0) doesn't have a [-URN](https://learn.microsoft.com/en-us/cli/azure/vm/image?view=azure-cli-latest#az-vm-image-accept-terms-examples) parameter. – Ayan Mullick Jan 23 '23 at 17:51

1 Answers1

0

I would use the following powershell command (assume some of the variables are already gotten like Gallery Name and Image Definition:

$version = Get-AzGalleryImageVersion -ResourceGroupName $ResourceGroup -GalleryName $computeGallery.Name -GalleryImageDefinitionName $imageDefinition.Name | Select-Object -Property Name | Sort-Object -Bottom 1;
Lenard Bartha
  • 348
  • 1
  • 9