使用 Azure PowerShell 在 Azure 市场中查找并使用 VM 映像Find and use VM images in the Azure Marketplace with Azure PowerShell

本文介绍如何使用 Azure PowerShell 在 Azure 市场中查找 VM 映像。This article describes how to use Azure PowerShell to find VM images in the Azure Marketplace. 然后,可以在创建 VM 时指定市场映像。You can then specify a Marketplace image when you create a VM.

你还可以使用 Azure 市场店面、Azure 门户Azure CLI 浏览可用的映像和产品/服务。You can also browse available images and offers using the Azure Marketplace storefront, the Azure portal, or the Azure CLI.

术语Terminology

Azure 中的市场映像具有以下属性:A Marketplace image in Azure has the following attributes:

  • 发布者:创建映像的组织。Publisher: The organization that created the image. 示例:Canonical、MicrosoftWindowsServerExamples: Canonical, MicrosoftWindowsServer
  • 产品/服务:发布者创建的一组相关映像的名称。Offer: The name of a group of related images created by a publisher. 示例:UbuntuServer、WindowsServerExamples: UbuntuServer, WindowsServer
  • SKU:产品/服务的实例,例如分发版的主要版本。SKU: An instance of an offer, such as a major release of a distribution. 示例:18.04-LTS、2019-DatacenterExamples: 18.04-LTS, 2019-Datacenter
  • 版本:映像 SKU 的版本号。Version: The version number of an image SKU.

若要在以编程方式部署 VM 时标识市场映像,请以参数的形式单独提供这些值。To identify a Marketplace image when you deploy a VM programmatically, supply these values individually as parameters. 有些工具接受映像 URN ,它将这些值合并,值之间用冒号 (:) 字符隔开:发布者 :产品/服务 :Sku :版本 。Some tools accept an image URN, which combines these values, separated by the colon (:) character: Publisher:Offer:Sku:Version. 在 URN 中,可将版本号替换为“latest”,这会选择最新的映像版本。In a URN, you can replace the version number with "latest", which selects the latest version of the image.

如果映像发布者提供附加许可条款和购买条款,则必须接受这些条款并启用编程部署。If the image publisher provides additional license and purchase terms, then you must accept those terms and enable programmatic deployment. 以编程方式部署 VM 时,还需要提供“购买计划” 参数。You'll also need to supply purchase plan parameters when deploying a VM programmatically. 请参阅部署具有市场条款的映像See Deploy an image with Marketplace terms.

常用 Windows 映像表Table of commonly used Windows images

此表显示了指示的发布者和产品/服务可用的 SKU 的子集。This table shows a subset of available Skus for the indicated Publishers and Offers.

发布者Publisher 产品/服务Offer SKUSku
MicrosoftWindowsServerMicrosoftWindowsServer WindowsServerWindowsServer 2019-Datacenter2019-Datacenter
MicrosoftWindowsServerMicrosoftWindowsServer WindowsServerWindowsServer 2019-Datacenter-Core2019-Datacenter-Core
MicrosoftWindowsServerMicrosoftWindowsServer WindowsServerWindowsServer 2019-Datacenter-with-Containers2019-Datacenter-with-Containers
MicrosoftWindowsServerMicrosoftWindowsServer WindowsServerWindowsServer 2016-Datacenter2016-Datacenter
MicrosoftWindowsServerMicrosoftWindowsServer WindowsServerWindowsServer 2016-Datacenter-Server-Core2016-Datacenter-Server-Core
MicrosoftWindowsServerMicrosoftWindowsServer WindowsServerWindowsServer 2016-Datacenter-with-Containers2016-Datacenter-with-Containers
MicrosoftWindowsServerMicrosoftWindowsServer WindowsServerWindowsServer 2012-R2-Datacenter2012-R2-Datacenter
MicrosoftWindowsServerMicrosoftWindowsServer WindowsServerWindowsServer 2012-Datacenter2012-Datacenter
MicrosoftSharePointMicrosoftSharePoint MicrosoftSharePointServerMicrosoftSharePointServer sp2019sp2019
MicrosoftSQLServerMicrosoftSQLServer SQL2019-WS2016SQL2019-WS2016 EnterpriseEnterprise
MicrosoftRServerMicrosoftRServer RServer-WS2016RServer-WS2016 EnterpriseEnterprise

在某个位置查找映像的一种方法是按顺序运行 Get-AzVMImagePublisherGet-AzVMImageOfferGet-AzVMImageSku cmdlet:One way to find an image in a location is to run the Get-AzVMImagePublisher, Get-AzVMImageOffer, and Get-AzVMImageSku cmdlets in order:

  1. 列出映像发布者。List the image publishers.
  2. 对于给定的发布者,列出其产品。For a given publisher, list their offers.
  3. 对于给定的产品,列出其 SKU。For a given offer, list their SKUs.

然后,对所选 SKU 运行 Get-AzVMImage,列出要部署的版本。Then, for a selected SKU, run Get-AzVMImage to list the versions to deploy.

  1. 列出发布者:List the publishers:

    Connect-AzAccount -Environment AzureChinaCloud
    $locName="<Azure location, such as China North>"
    Get-AzVMImagePublisher -Location $locName | Select PublisherName
    
  2. 填写你选择的发布者名称并列出产品/服务:Fill in your chosen publisher name and list the offers:

    $pubName="<publisher>"
    Get-AzVMImageOffer -Location $locName -PublisherName $pubName | Select Offer
    
  3. 填写你选择的产品/服务名称并列出 SKU:Fill in your chosen offer name and list the SKUs:

    $offerName="<offer>"
    Get-AzVMImageSku -Location $locName -PublisherName $pubName -Offer $offerName | Select Skus
    
  4. 填写你选择的 SKU 名称并获取映像版本:Fill in your chosen SKU name and get the image version:

    $skuName="<SKU>"
    Get-AzVMImage -Location $locName -PublisherName $pubName -Offer $offerName -Sku $skuName | Select Version
    

Get-AzVMImage 命令的输出中,可以选择要部署新虚拟机的版本映像。From the output of the Get-AzVMImage command, you can select a version image to deploy a new virtual machine.

以下示例显示了命令及其输出的完整序列:The following example shows the full sequence of commands and their outputs:

$locName="China North"
Get-AzVMImagePublisher -Location $locName | Select PublisherName

部分输出:Partial output:

PublisherName
-------------
...
360-cn
A10Networks
a10networks-cn
afajr-cn
aibaby
aigauss
airdoc
airdoc-cn
alauda
AllMobilize
alteonva
Antshares
arcblock-cn
arctron
array_networks
array_networks-cn
AsiaInfo.DeepSecurity
attittu-cn
AzureChinaMarketplace
AzureDatabricks
...

对于“MicrosoftWindowsServer”发布者:For the MicrosoftWindowsServer publisher:

$pubName="MicrosoftWindowsServer"
Get-AzVMImageOffer -Location $locName -PublisherName $pubName | Select Offer

输出:Output:

Offer
-----
WindowsServer
WindowsServerSemiAnnual

对于“WindowsServer”产品/服务:For the WindowsServer offer:

$offerName="WindowsServer"
Get-AzVMImageSku -Location $locName -PublisherName $pubName -Offer $offerName | Select Skus

部分输出:Partial output:

Skus
----
2008-R2-SP1
2008-R2-SP1-smalldisk
2008-R2-SP1-zhcn
2012-Datacenter
2012-datacenter-gensecond
2012-Datacenter-smalldisk
2012-datacenter-smalldisk-g2
2012-Datacenter-zhcn
2012-datacenter-zhcn-g2
2012-R2-Datacenter
2012-r2-datacenter-gensecond
2012-R2-Datacenter-smalldisk
2012-r2-datacenter-smalldisk-g2
2012-R2-Datacenter-zhcn
2012-r2-datacenter-zhcn-g2
2016-Datacenter
2016-datacenter-gensecond
2016-datacenter-gs
2016-Datacenter-Server-Core
2016-datacenter-server-core-g2
2016-Datacenter-Server-Core-smalldisk
2016-datacenter-server-core-smalldisk-g2
2016-Datacenter-smalldisk
2016-datacenter-smalldisk-g2
2016-Datacenter-with-Containers
2016-datacenter-with-containers-g2
2016-datacenter-with-containers-gs
2016-Datacenter-zhcn
2016-datacenter-zhcn-g2
2016-Nano-Server
2019-Datacenter
2019-Datacenter-Core
2019-datacenter-core-g2
2019-Datacenter-Core-smalldisk
2019-datacenter-core-smalldisk-g2
2019-Datacenter-Core-with-Containers
...

然后,对于 2019-Datacenter SKU:Then, for the 2019-Datacenter SKU:

$skuName="2019-Datacenter"
Get-AzVMImage -Location $locName -PublisherName $pubName -Offer $offerName -Sku $skuName | Select Version

现在可以将所选发布者、产品/服务、SKU 和版本合并到 URN 中(由“:”分隔的值)。Now you can combine the selected publisher, offer, SKU, and version into a URN (values separated by :). 使用 New-AzVM cmdlet 创建 VM 时,使用 --image 参数传递此 URN。Pass this URN with the --image parameter when you create a VM with the New-AzVM cmdlet. 还可以将 URN 中的版本号替换为 "latest" 以获取映像的最新版本。You can optionally replace the version number in the URN with "latest" to get the latest version of the image.

如果使用资源管理器模板部署 VM,请在 imageReference 属性中单独设置映像参数。If you deploy a VM with a Resource Manager template, then you'll set the image parameters individually in the imageReference properties.

部署具有市场条款的映像Deploy an image with Marketplace terms

Azure 市场中的某些 VM 映像具有附加许可条款和购买条款,你必须接受这些条款,然后才能以编程方式部署这些映像。Some VM images in the Azure Marketplace have additional license and purchase terms that you must accept before you can deploy them programmatically.

若要从此类映像部署 VM,需要同时接受映像的条款并启用编程部署。To deploy a VM from such an image, you'll need to both accept the image's terms and enable programmatic deployment. 只需对每个订阅执行一次此操作。You'll only need to do this once per subscription. 此后,每次以编程方式从映像部署 VM 时,还需要指定“购买计划” 参数。Afterward, each time you deploy a VM programmatically from the image you'll also need to specify purchase plan parameters.

以下部分介绍如何执行这些操作:The following sections show how to:

  • 了解市场映像是否具有附加许可条款Find out whether a Marketplace image has additional license terms
  • 以编程方式接受条款Accept the terms programmatically
  • 以编程方式部署 VM 时提供购买计划参数Provide purchase plan parameters when you deploy a VM programmatically

查看计划属性View plan properties

若要查看映像的购买计划信息,请运行 Get-AzVMImage cmdlet。To view an image's purchase plan information, run the Get-AzVMImage cmdlet. 如果输出中的 PurchasePlan 属性不是 null,则映像有条款,在以编程方式部署前需要接受该条款。If the PurchasePlan property in the output is not null, the image has terms you need to accept before programmatic deployment.

例如,Windows Server 2019 Datacenter 映像没有附加条款,因此,PurchasePlan 信息为 nullFor example, the Windows Server 2019 Datacenter image doesn't have additional terms, so the PurchasePlan information is null:

$version = "2019.0.20190115"
Get-AzVMImage -Location $locName -PublisherName $pubName -Offer $offerName -Skus $skuName -Version $version

输出:Output:

Id               : /Subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Providers/Microsoft.Compute/Locations/chinanorth/Publishers/MicrosoftWindowsServer/ArtifactTypes/VMImage/Offers/WindowsServer/Skus/2016-Datacenter/Versions/2019.0.20190115
Location         : chinanorth
PublisherName    : MicrosoftWindowsServer
Offer            : WindowsServer
Skus             : 2019-Datacenter
Version          : 2019.0.20190115
FilterExpression :
Name             : 2019.0.20190115
OSDiskImage      : {
                     "operatingSystem": "Windows"
                   }
PurchasePlan     : null
DataDiskImages   : []

后续步骤Next steps

若要使用基本映像信息通过 New-AzVM cmdlet 快速创建虚拟机,请参阅使用 PowerShell 创建 Windows 虚拟机To create a virtual machine quickly with the New-AzVM cmdlet by using basic image information, see Create a Windows virtual machine with PowerShell.

有关使用 Azure 市场映像在共享映像库中创建自定义映像的更多信息,请参阅在创建映像时提供 Azure 市场购买计划信息For more information on using Azure Marketplace images to create custom images in a shared image gallery, see Supply Azure Marketplace purchase plan information when creating images.