PowerCLI Reference

New-Template

Synopsis

This cmdlet creates a new virtual machine template.

Syntax

New-Template [-VM] <VirtualMachine> [-Name] <String> [-Location] <VIContainer> [-Datastore <StorageResource>] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

New-Template [[-Name] <String>] [-Location <VIContainer>] [-VMHost <VMHost>] [-Datastore <StorageResource>] [-DiskStorageFormat <VirtualDiskStorageFormat>] -Template <Template> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

New-Template [[-Name] <String>] [-Location <VIContainer>] -VMHost <VMHost> [-TemplateFilePath] <String> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

Related Commands

Online version
Get-Template
Remove-Template
Set-Template

Detailed Description

This cmdlet creates a new template based on the specified virtual machine.
You can also create a new template by cloning an existing one. You can also register an existing template to the vCenter Server inventory.

Parameters

NameTypeDescriptionRequired?Pipeline InputDefault Value
NameStringSpecifies a name for the new template.truefalse
TemplateFilePathStringSpecifies the datastore path to the file you want to use to register the new template.truefalse
VMVirtualMachineSpecifies the virtual machine from which you want to create the new template.truetrue (ByValue)
LocationVIContainerSpecifies the location where you want to place the new template.truetrue (ByValue)
ConfirmSwitchParameterIf the value is $true, indicates that the cmdlet asks for confirmation before running. If the value is $false, the cmdlet runs without asking for user confirmation.falsefalse
DatastoreStorageResourceSpecifies the datastore or the datastore cluster where you want to store the new template.falsefalse
DiskStorageFormatVirtualDiskStorageFormatSpecifies the disk storage format of the new template. This parameter accepts Thin, Thick, and EagerZeroedThick values.falsefalse
RunAsyncSwitchParameterIndicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter run "help About_RunAsync" in the VMware PowerCLI console.falsefalse
ServerVIServer[]Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer.falsefalse
TemplateTemplateSpecifies a template you want to clone.truetrue (ByValue)
VMHostVMHostSpecifies the host where you want to create the new template.falsefalse
WhatIfSwitchParameterIndicates that the cmdlet is run only to display the changes that would be made and actually no objects are modified.falsefalse

Return Type

The newly created Template object

Notes

Examples

-------------- Example 1 --------------

$myVM = Get-VM -Name "MyVM1"
$drsCluster=Get-DatastoreCluster "MyDatastoreCluster"
New-Template -VM $myVM -Name "MyTemplate" -Datastore $drsCluster -Location Datacenter2

Creates a template named MyTemplate from the MyVM1 virtual machine and stores it in the MyDatastoreCluster datastore cluster in the Datacenter2 datacenter.

-------------- Example 2 --------------

$myFolder = Get-Folder -Name "MyFolder1"
New-Template -Name "MyTemplate1" -TemplateFilePath "[Storage1] templatefolder/template.vmtx" -Location $myFolder -VMHost (Get-VMHost)

Registers the existing MyTemplate1 template to a vCenter Server inventory folder by using the specified template file.

-------------- Example 3 --------------

$myTemplate = Get-Template -Name "MyTemplate1"
$myDs = Get-Datastore -Name "MyDatastore1"
New-Template -Template $myTemplate -Name "MyTemplate2" -Datastore $myDs -Location "Datacenter2"

Creates the MyTemplate2 template by cloning an existing template and stores the new template in the specified datastore in the Datacenter2 datacenter.


Copyright © VMware, Inc. All rights reserved.