azure - 如何使用 Powershell 7 Get-AzVMImage 获取最新版本

标签 azure powershell azure-devops azure-devops-rest-api

我正在尝试使用 Azure Powershell 7 commandlet 获取最新版本的 Canonical UbuntuServer 18.04-LTS。

这是我的查询示例:

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

身份验证后,我尝试运行该命令行开关,但收到以下错误:

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

但是,如果我将 -Version 标志硬编码为已知版本号,如下所示:

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

我收到成功的回复:

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   : []

这篇关于如何查找和使用市场图像的 Azure 文章 Find and use Azure Marketplace VM images with Azure PowerShell状态“...对于 SKU,使用 Get-AzVMImage 列出镜像的版本。如果要使用最新镜像而不是特定的旧版本,也可以使用最新版本。”

作为替代方案,它还提到您可以使用 URN 格式代替“...这些值可以单独传递或作为图像 URN 传递,组合由冒号 (:) 分隔的值。例如:Publisher:Offer :Sku:版本,您可以将URN中的版本号替换为latest,以使用最新版本的镜像。"

有谁知道我需要更改什么才能使用-版本“最新”

我考虑首先查询所有版本并获取列表中的最后一个版本。然后,我将 $version 变量设置为最后一个版本号。但这似乎与 Azure 文档中的建议背道而驰。

最佳答案

我将使用以下 powershell 命令(假设已经获取了一些变量,例如图库名称和图像定义:

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

关于azure - 如何使用 Powershell 7 Get-AzVMImage 获取最新版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69560013/

相关文章:

azure - 必须为管道分离 YAML 文件

sql-server - Azure 数据工厂上的存储过程失败并显示错误消息 : The length of execution output is over limit (around 1M currently)

python - 使用 Azure Functions 中的 Python 根据 Azure Blob 存储中的模式匹配检查 Blob 是否存在

azure - 如何确定 Azure EventGrid 消息传递失败的原因?

Azure DevOps 管道 yml 快捷方式可能吗?

azure-devops - VSTS 在 Pull Request 分支上运行构建

git - Azure Devops Pipeline 运行会导致 Git 错误?

powershell - 按属性名称过滤 cim 实例类

powershell - 如何使用Powershell获取网站HostHeader

powershell - 如何在同一个输入框中有多个输入字段