Previous Topic: dpmhv-createVirtFloppy (Cmdlet) Command--Create a Virtual FloppyNext Topic: dpmhv-createVMFromTemplate (Funclet) Command--Create a VM Using a Template


dpmhv-createVM (Funclet) Command--Create a VM

The dpmhv-createVM command lets you create a VM. This command creates VM without system components such as network adapter or hard disks. Upon creating VM, you can create system components using respective commands.

This command has the following format:

dpmhv-createVM 
-host hostname 
-name name 
[-path pathname] 
[-template templatename]
[-templateid vmguid]
[-mem mem]
[-cpus cpus]
[-cpuidlimit limit] 
[-cpureserve reserve]
[-cpulimit limit]
[-cpuweight weight]
[-startAction {none|auto|always}]
[-startDelay delay] 
[-stopAction {save,off,shutdown}] 
[-recoveryAction {none,restart,revert}]
[-retval] 
[-silent]
-host hostname

Specifies the name of the Hyper-V server host.

-name name

(Optional) Specifies the name of the VM.

Note: The name of the VM must be unique.

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

-template templatename

(Optional) Specifies the name of the existing VM. This option is used to copy the configuration settings of existing VMs to create new VMs. We recommend not creating VMs from existing VMs. Two VMs share resources such as virtual disk and cannot be run simultaneously.

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

-templateid vmguid

(Optional) Specifies the unique ID (GUID) of the existing VM. This option is used to copy the configuration settings of the existing VMs to create new VMs. We recommend not creating VMs from existing VMs. Two VMs can share resources such as virtual disks and cannot be run simultaneously.

Default: -1

Note: This option does not represent the template ID from VM catalog, but it represents the existing VM in Hyper-V environment.

-mem mem

(Optional) Specifies the RAM memory in megabytes (MB) for the VM that you want to create.

Default: -1

-cpus cpus

(Optional) Specifies the number of CPU cores to assign to the VM.

-cpuidlimit limit

(Optional) Specifies the limit of CPU ID functionality of VM. This option improves the compatibility with legacy operating systems such as Windows NT.

Default: -1

-cpureserve reserve

(Optional) Specifies the percentage of the CPU that you want to reserve for the VM. If this option is not specified, Hyper-V server assigns CPU cycles based on the overall system usage.

Default: -1

-cpulimit limit

(Optional) Specifies the limit for the number of CPU resources used by a VM. This option improves the compatibility while moving VMs between physical hosts with different CPU capabilities.

Default: -1

-cpuweight weight

(Optional) Specifies the relative weight of the virtual machine. This option controls resource allocation when more than one VM is running. Valid entry: integer, 1-10000.

Default: -1

-startAction {none,auto,always}

(Optional) Specifies the action that you want to perform on the VM when the Hyper-V host starts up. Options include the following:

none

Performs no action.

auto

Starts the VM automatically.

Note: Use this option if the VM was running before the Hyper-V host is shut down.

always

Starts the VM always.

-startDelay delay

(Optional) Specifies the delay in seconds to start the VM after the Hyper-V host is up and running.

Default: -1

-stopAction {save,off,shutdown}

(Optional) Specifies the action that you want to perform on the VM when the physical Hyper-V shuts down. Options include the following:

save

Suspends the VM.

off

Power offs the VM.

shutdown

Shuts down the system.

-recoveryAction {none,restart,revert}

(Optional) Specifies the action to perform on the VM after the Hyper-V host restarts from unexpected shutdown. Options include the following:

none

Performs no action.

restart

Restart the VM.

revert

Reverts to the last snapshot of the VM.

-retval

Returns a value for further processing.

-silent

Specifies not to direct the output to the screen.

Return Value

This command returns a string with the unique identifier (GUID) of newly created VM.

Example: Create a VM with default settings

This example creates VM, "TestVM" with default settings.

dpmhv-createVM -host hvserver -name TestVM

Example: Create a VM with default settings in user-defined directory

This example creates VM,"TestVM" with default settings in user-defined directory.

dpmhv-createVM -host hvserver -name TestVM -path c:\VMs\TestVM

Example: Create a VM with custom memory and CPU core values

This example creates VM,"TestVM" with custom memory and CPU core values.

dpmhv-createVM -host hvserver -name TestVM -mem 1024 -cpus 2