Edit

Share via


Save-AzVMImage

Saves a virtual machine as a VMImage.

Syntax

ResourceGroupNameParameterSetName (Default)

Save-AzVMImage
    [-Name] <String>
    [-DestinationContainerName] <String>
    [-VHDNamePrefix] <String>
    [[-Path] <String>]
    [-ResourceGroupName] <String>
    [-Overwrite]
    [-AsJob]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

IdParameterSetName

Save-AzVMImage
    [-DestinationContainerName] <String>
    [-VHDNamePrefix] <String>
    [[-Path] <String>]
    [-Id] <String>
    [-Overwrite]
    [-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.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments: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.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:2
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Id

Specifies the Resource ID of the virtual machine.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

IdParameterSetName
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Name

Specifies a name.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:VMName

Parameter sets

ResourceGroupNameParameterSetName
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Overwrite

Indicates that this cmdlet overwrites any VHDs that have the same prefix in the destination container.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:4
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Path

The file path in which the template of the captured image is stored.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:5
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ResourceGroupName

Specifies the name of the resource group of the virtual machine.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ResourceGroupNameParameterSetName
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments: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.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:VirtualHardDiskNamePrefix

Parameter sets

(All)
Position:3
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

String

SwitchParameter

Outputs

PSComputeLongRunningOperation