Previous Topic: dpmhv-changeVMState (Cmdlet) Command--Change the State of a VMNext Topic: dpmhv-createVirtDisk (Funclet) Command--Create a Virtual Disk


dpmhv-createTemplateFromVM (Funclet) Command--Create a Template from a VM

The dpmhv-createTemplateFromVM command creates the template using an existing VM. You can use the template to create multiple VMs.

The template copies the VM specifications and virtual hard disks attached to the VM. If you create a template using the VM with snapshots, only the current state is exported without snapshots. This command creates a template catalog for each Hyper-V server. The template catalog is maintained and can be queried from the following location: %ALLUSERSPROFILE%\ca\vpm\Hyper-V_Templates\TemplateCatalog.xml

This command has the following format:

dpmhv-createTemplateFromVM 
-host hostname 
-vm vmname|-vmid vmguid 
-template templatename 
[-async] 
[-path pathname] 
[-description description]
[-retval] 
[-silent]
-host hostname

Specifies the name of the Hyper-V server host.

-vm vmname

Specifies the name of the VM.

-vmid vmguid

Specifies the unique ID of the VM.

-template templatename

Specifies the name of the generic template created in the template catalog.

Note: The template name must be unique in the local template catalog.

-async

(Optional) Specifies the option to execute the command asynchronously. By default, this command is executed synchronously.

Note: If this command completes the execution before executing this option, it returns a job ID that is used to view the operation status.

-dest pathname

(Optional) Specifies the path of the VM that you want to create (template is stored). If this option is not specified, VM is created in the Hyper-V Server default location. The name of the template created is stored in the following location: %ALLUSERSPROFILE%\ca\vpm\Hyper-V_Templates.

Note: We recommend not creating VMs in the Hyper-V default location. It conflicts with virtual disk image file names that do not change when creating VMs using templates.

-description description

(Optional) Specifies the template description.

-retval

Returns a value for further processing.

-silent

Specifies not to direct the output to the screen.

Return Value

When the dpmhv-createTemplateFromVM command is executed synchronously, it returns an empty string. If executed asynchronously, a string representing job ID is passed to dpmhv-getJobErrorInfo, dpmhv-getJobInfo, or dpmhv-getJobStatus. If an error occurs during execution, the command reports an exception.

Example: Create a Template from a VM

This example creates the template, "MyTemplate" from the VM, "TestVM."

dpmhv-createTemplateFromVM -vm TestVM -template MyTemplate -host hvserver