Save-AzureRmVMImage

Saves a virtual machine as a VMImage.

Warning

The AzureRM PowerShell module has been officially deprecated as of February 29, 2024. Users are advised to migrate from AzureRM to the Az PowerShell module to ensure continued support and updates.

Although the AzureRM module may still function, it's no longer maintained or supported, placing any continued use at the user's discretion and risk. Please refer to our migration resources for guidance on transitioning to the Az module.

Syntax

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

Description

The Save-AzureRmVMImage 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-AzureRmVM 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

PS C:\> Set-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -Generalized 
PS C:\> Save-AzureRmVMImage -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.

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

Inputs

String

SwitchParameter

Outputs

PSComputeLongRunningOperation