你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Save-AzVMImage
Saves a virtual machine as a VMImage.
Syntax
Save-AzVMImage
[-Name] <String>
[-DestinationContainerName] <String>
[-VHDNamePrefix] <String>
[-Overwrite]
[[-Path] <String>]
[-ResourceGroupName] <String>
[-AsJob]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Save-AzVMImage
[-DestinationContainerName] <String>
[-VHDNamePrefix] <String>
[-Overwrite]
[[-Path] <String>]
[-Id] <String>
[-AsJob]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
The Save-AzVMImage cmdlet saves a virtual machine as a VMImage. Before you create a virtual machine image, sysprep the virtual machine, and then mark it as generalized by using the Set-AzVM cmdlet. The output of this cmdlet is a JavaScript Object Notation (JSON) template. You can deploy virtual machines from your captured image.
Examples
Example 1: Capture a virtual machine
Set-AzVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -Generalized
Save-AzVMImage -ResourceGroupName "ResourceGroup11" -VMName "VirtualMachine07" -DestinationContainerName "VMContainer01" -VHDNamePrefix "VM07"
The first command marks the virtual machine named VirtualMachine07 as generalized. The second command captures a virtual machine named VirtualMachine07 as a VMImage. The Output property returns a JSON template.
Example 2
Saves a virtual machine as a VMImage. (autogenerated)
Save-AzVMImage -DestinationContainerName 'VMContainer01' -Name 'VirtualMachine07' -Path '/home/admin/.ssh/authorized_keys' -ResourceGroupName 'ResourceGroup11' -VHDNamePrefix 'VM07'
Parameters
-AsJob
Run cmdlet in the background and return a Job to track progress.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.
Type: | IAzureContextContainer |
Aliases: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DestinationContainerName
Specifies the name of a container inside the "system" container that you want to hold your images. If the container doesn't exist, it is created for you. The virtual hard disks (VHDs) that constitute the VMImage reside in the container that this parameter specifies. If the VHDs are spread across multiple storage accounts, this cmdlet creates one container that has this name in each storage account. The URL of the saved image is similar to: https://<storageAccountName>.blob.core.windows.net/system/Microsoft.Compute/Images/<imagesContainer>/<vhdPrefix-osDisk>.xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.vhd.
Type: | String |
Position: | 2 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Id
Specifies the Resource ID of the virtual machine.
Type: | String |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Name
Specifies a name.
Type: | String |
Aliases: | VMName |
Position: | 1 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Overwrite
Indicates that this cmdlet overwrites any VHDs that have the same prefix in the destination container.
Type: | SwitchParameter |
Position: | 4 |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Path
The file path in which the template of the captured image is stored.
Type: | String |
Position: | 5 |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-ResourceGroupName
Specifies the name of the resource group of the virtual machine.
Type: | String |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-VHDNamePrefix
Specifies the prefix in the name of the blobs that constitute the storage profile of the VMImage. For example, a prefix vhdPrefix for an operating system disk results in the name vhdPrefix-osdisk.<guid>.vhd.
Type: | String |
Aliases: | VirtualHardDiskNamePrefix |
Position: | 3 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |