你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
New-AzGalleryImageVersion
创建库映像版本。
语法
New-AzGalleryImageVersion
[-ResourceGroupName] <String>
[-GalleryName] <String>
[-GalleryImageDefinitionName] <String>
[-Name] <String>
[-AsJob]
-Location <String>
[-DataDiskImage <GalleryDataDiskImage[]>]
[-OSDiskImage <GalleryOSDiskImage>]
[-PublishingProfileEndOfLifeDate <DateTime>]
[-PublishingProfileExcludeFromLatest]
[-ReplicaCount <Int32>]
[-SourceImageId <String>]
[-SourceImageVMId <String>]
[-StorageAccountType <String>]
[-Tag <Hashtable>]
[-TargetRegion <Hashtable[]>]
[-TargetExtendedLocation <Hashtable[]>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
创建库映像版本。
示例
示例 1:从虚拟机创建映像版本
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$sourceImageVMId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myVMRG/providers/Microsoft.Compute/virtualMachines/myVM"
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageVMId $sourceImageVMId
将虚拟机中的新映像版本添加到映像定义中。
示例 2:从托管映像创建映像版本
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$sourceImageId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myImageRG/providers/Microsoft.Compute/images/myImage"
$storageAccountType = "Standard_LRS"
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -StorageAccountType $storageAccountType -SourceImageId $sourceImageId
将托管映像中的新映像版本添加到映像定义中。
示例 3:从另一个映像版本创建映像版本
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$sourceImageId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myImageRG/providers/Microsoft.Compute/galleries/myOtherGallery/images/myImageDefinition/versions/1.0.0"
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageId $sourceImageId
将映像版本复制到另一个映像版本
示例 4:从托管磁盘添加新映像版本
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$osDisk = @{Source = @{Id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myDiskRG/providers/Microsoft.Compute/disks/myOSDisk" }}
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -OSDiskImage $osDisk
从托管磁盘创建映像版本
示例 5:从托管磁盘添加新映像版本并添加其他数据磁盘
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$osDisk = @{Source = @{Id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myDiskRG/providers/Microsoft.Compute/disks/myOSDisk" }}
$dataDisk0 = @{Source = @{Id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myDiskRG/providers/Microsoft.Compute/disks/myDataDisk" }; Lun = 0; }
$dataDisks = @($dataDisk0)
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -OSDiskImage $osDisk -DataDiskImage $dataDisks
通过指定 OS 和数据磁盘创建映像版本
示例 6:从 OS 磁盘的快照中添加新的映像版本
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$osSnapshot = @{Source = @{Id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mySnapshotRG/providers/Microsoft.Compute/snapshots/myOSSnapshot" }}
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -OSDiskImage $osSnapshot
从磁盘快照创建映像版本
示例 7:从 OS 磁盘的快照中添加新的映像版本,并添加其他数据磁盘
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$osSnapshot = @{Source = @{Id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mySnapshotRG/providers/Microsoft.Compute/snapshots/myOSSnapshot" }}
$dataSnapshot0 = @{Source = @{Id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mySnapshotRG/providers/Microsoft.Compute/snapshots/myDataSnapshot" }; Lun = 0; }
$dataDisks = @($dataSnapshot0)
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -OSDiskImage $osSnapshot -DataDiskImage $dataDisks
通过指定 OS 和数据磁盘的快照来创建映像版本。
示例 8:从磁盘和快照的组合中添加新的映像版本
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$osSnapshot = @{Source = @{Id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mySnapshotRG/providers/Microsoft.Compute/snapshots/myOSSnapshot" }}
$dataDisk0 = @{Source = @{Id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myDiskRG/providers/Microsoft.Compute/disks/myDataDisk" }; Lun = 0; }
$dataDisks = @($dataDisk0)
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -OSDiskImage $osSnapshot -DataDiskImage $dataDisks
通过将快照指定为 OS 磁盘,将托管磁盘指定为数据磁盘来创建映像版本。
示例 9:添加新映像版本并将其复制到其他区域。
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$sourceImageId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myVMRG/providers/Microsoft.Compute/virtualMachines/myVM"
$replicaCount = 1
$storageAccountType = "Standard_ZRS"
$region_eastus = @{Name = 'East US';ReplicaCount = 3;StorageAccountType = 'Standard_LRS'}
$region_westus = @{Name = 'West US'}
$region_ukwest = @{Name = 'UK West';ReplicaCount = 2}
$region_southcentralus = @{Name = 'South Central US';StorageAccountType = 'Standard_LRS'}
$targetRegions = @($region_eastus, $region_westus, $region_ukwest, $region_southcentralus)
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageId $sourceImageId -ReplicaCount 1 -StorageAccountType $storageAccountType -TargetRegion $targetRegions
在四个区域中创建映像版本。 在此示例中,全局副本计数为 1,全局存储帐户类型Standard_ZRS。 美国东部将有 3 个副本,每个副本存储在Standard_LRS帐户存储中。 美国西部将从全局设置继承,并在Standard_ZRS上存储 1 个副本。 英国西部将有一个副本计数 2 存储在Standard_ZRS。 美国中南部将有一个副本存储在Standard_LRS。
示例 10:在多个区域中添加具有加密的新映像版本
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$sourceImageId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myVMRG/providers/Microsoft.Compute/virtualMachines/myVM"
$replicaCount = 1
$storageAccountType = "Standard_ZRS"
# East US regional settings
$eastUSdes = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myDESrg/providers/Microsoft.Compute/diskEncryptionSets/myEastUSDES"
$encryption_eastus_os = @{DiskEncryptionSetId = $eastUSdes }
$encryption_eastus_dd0 = @{DiskEncryptionSetId = $eastUSdes; Lun = 0 }
$encryption_eastus_dd = @($encryption_eastus_dd0)
$eastus_encryption = @{OSDiskImage = $eastus_encryption_os; DataDiskImages = $eastus_encryption_dd }
$region_eastus = @{Name = 'East US';ReplicaCount = 3;StorageAccountType = 'Standard_LRS'; Encryption = $encryption_eastus}
# West US regional settings
$westUS2des = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myDESrg/providers/Microsoft.Compute/diskEncryptionSets/myWestUSDES"
$encryption_westus_os = @{DiskEncryptionSetId = $westUSdes }
$encryption_westus_dd0 = @{DiskEncryptionSetId = $westUSdes; Lun = 0 }
$encryption_westus_dd = @($encryption_westus_dd0)
$westus_encryption = @{OSDiskImage = $encryption_westus_os; DataDiskImages = $encryption_westus_dd }
$region_westus = @{Name = 'West US'; Encryption = $westus_encryption}
# Create images
$targetRegions = @($region_eastus, $region_westus)
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageId $sourceImageId -TargetRegion $targetRegions
在两个区域中创建具有加密的映像版本。 磁盘加密集是区域资源,必须在每个区域中使用不同的磁盘加密集。
示例 11:创建映像版本并将其从最新版本中排除
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageId $sourceImageId -PublishingProfileExcludeFromLatest
将新的映像版本添加到映像定义中,但将其排除在其映像定义中考虑的最新版本。
示例 12:创建映像版本并设置其生命周期结束日期
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "myImage"
$galleryImageVersionName = "1.0.0"
$location = "eastus"
$endOfLifeDate = "2024-08-02T00:00:00+00:00"
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageId $sourceImageId -PublishingProfileEndOfLifeDate $endOfLifeDate
本示例在 mignight UTC 的映像版本设置为 2024 年 8 月 2 日。该示例的生命周期结束日期设置为 2024 年 8 月 2 日。 可以为映像定义和映像版本指定生命周期结束日期。 映像版本仍可在生命周期结束日期后使用。
示例 13:为机密 VM 创建映像版本
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "cvmImage"
$galleryImageVersionName = "1.0.0"
$location = "North Europe"
$sourceImageId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myVMRG/providers/Microsoft.Compute/virtualMachines/myVM"
$cvmDiskEncryptionSetId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myVMRG/providers/Microsoft.Compute/diskEncryptionSets/cvmDiskEncryptionSet"
$dataDiskEncryptionSetId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myVMRG/providers/Microsoft.Compute/diskEncryptionSets/dataDiskEncryptionSet"
$cvmOsDiskEncryption = @{CVMEncryptionType='EncryptedWithCmk'; CVMDiskEncryptionSetID=$cvmDiskEncryptionSetId}
$cvmDataDiskEncryption_lun0 = @{DiskEncryptionSetId = $dataDiskEncryptionSetId ; Lun = 0}
$cvmDataDiskEncryption = @($cvmDataDiskEncryption_lun0)
$cvmEncryption = @{OSDiskImage = $cvmOsDiskEncryption; DataDiskImages = $cvmDataDiskEncryption}
$region_northEurope = @{Name = 'NorthEurope';ReplicaCount = 3;StorageAccountType = 'Standard_LRS'; Encryption = $cvmEncryption}
$targetRegions = @($region_northEurope)
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageId $sourceImageId -ReplicaCount 1 -StorageAccountType "Standard_LRS" -TargetRegion $targetRegions
在此示例中,使用客户托管密钥的机密 VM (CVM) 映像(CMK)在支持 ConfidentialVM 安全类型的映像定义下创建。
示例 14:创建具有目标扩展位置的映像版本
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$galleryImageDefinitionName = "cvmImage"
$galleryImageVersionName = "1.0.0"
$location = "EastUs"
$sourceImageId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myVMRG/providers/Microsoft.Compute/virtualMachines/myVM"
$replicaCount = 1
$extendedLocation = @{Name = 'microsoftlosangeles1';Type='EdgeZone'}
$edgezone_losangeles = @{Location = "westus";ExtendedLocation=$extendedLocation;ReplicaCount = 3;StorageAccountType = 'Standard_LRS'}
$targetExtendedLocations = @($edgezone_losangeles)
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageId $sourceImageId -ReplicaCount 1 -StorageAccountType "Standard_LRS" -TargetExtendedLocation $targetExtendedLocations
此示例为目标扩展位置属性创建哈希表,并使用 -TargetExtendedLocation 参数传入。
参数
-AsJob
在后台运行 cmdlet
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Confirm
在运行 cmdlet 之前,提示你进行确认。
类型: | SwitchParameter |
别名: | cf |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-DataDiskImage
数据磁盘映像。 例如 @{Source = @{Id = <source_id>};Lun = 1;SizeInGB = 100;HostCaching = “ReadOnly” }
类型: | GalleryDataDiskImage[] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-DefaultProfile
用于与 Azure 通信的凭据、帐户、租户和订阅。
类型: | IAzureContextContainer |
别名: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-GalleryImageDefinitionName
库的名称。
类型: | String |
别名: | GalleryImageName |
Position: | 2 |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-GalleryName
库的名称。
类型: | String |
Position: | 1 |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-Location
资源位置
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-Name
库映像版本的名称。
类型: | String |
别名: | GalleryImageVersionName |
Position: | 3 |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-OSDiskImage
OS 磁盘映像,例如 @{Source = @{Id = <source_id>};SizeInGB = 100;HostCaching = “ReadOnly” }
类型: | GalleryOSDiskImage |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-PublishingProfileEndOfLifeDate
库映像版本的生命周期结束日期。
类型: | DateTime |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-PublishingProfileExcludeFromLatest
如果已设置,则从最新版本的映像定义部署的虚拟机不会使用此映像版本。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-ReplicaCount
要为每个区域创建的映像版本的副本数。
类型: | Int32 |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-ResourceGroupName
资源组的名称。
类型: | String |
Position: | 0 |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-SourceImageId
要从中创建映像版本的源映像的 ID。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-SourceImageVMId
源虚拟机的资源 ID。 仅当捕获虚拟机以源此库映像版本时才是必需的。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-StorageAccountType
指定要用于存储映像的存储帐户类型。 此属性不可更新。 可用值为Standard_LRS、Standard_ZRS和Premium_LRS。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Tag
资源标记
类型: | Hashtable |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-TargetExtendedLocation
要将映像版本复制到的目标扩展位置。 此属性可更新。
类型: | Hashtable[] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-TargetRegion
要将映像版本复制到的目标区域。
类型: | Hashtable[] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 cmdlet 未运行。
类型: | SwitchParameter |
别名: | wi |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |