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.