One of the most basic things you will do within a virtual infrastructure is creating virtual machines. Adding one new virtual machine like this is fine, but if you have to repeat this proces multiple times it might be more usefull to use a script containing the PowerCLI cmdlet New-VM.

You can use the New-VM cmdlet in conjuction with templates and customization specifications, which can also be created through the use of PowerCLI. Those cmdlets will be handled in articles yet to come.

There are a lot of parameters that can be used with the New-VM cmdlet but at the very least you should enter a virtual machine name and cluster / resourcepool.

If you also want to specify the location of the VDMK files you can add the Datastore parameter

When you want to clone a virtual machine you can add the “-VM” parameter

To import a virtual machine you will need to first get the folder name on a specific datastore and load that into a variable. You can then use that variable together with the new-vm cmdlet to import a virtual machine

By default the New-VM cmlet will create a virtual machine that contains 1 vCPU, 256 MB memory and a 4GB disk and a NIC connected at “internal network”. To change this you can add parameters like this.

As mentioned there are a lot of parameters you can use and the above examples only contain about half. I won’t write them all out in detail, instead I will give a summation for the rest of the parameters and a description.

VMhostSpecifies a vSphere host to place the virtual machine on
TemplateEnables you to create a virtual machine based of a template
AlternateGuestNameAllows you to change the guest OS name. Only to be used when you use the parameter “otherGuest” or “otherGuest64”.
CDAdd a CD drive to the guest or not
ConfirmWhether the cmdlet should ask for confirmation
DescriptionAdding a description in the notes field of a virtual machine
DiskStorageFormatSpecify the virtual disk format Thin or Thick
DrsAutomationLevelSpecifies the level of DRS automation applied to the virtual machine
FloppyAdd a Floppy drive to the guest or not
GuestIDWhat will the OS be, each OS has it’s own code. For reference you can look at this site
HAIsolationResponseIndicate the HA response for the virtual machine in case of host isolation
HARestartPrioritySpecify the HA restart priority of the virtual machine in case a host fails
LocationFolder placement of the virtual machine
OSCustomizationSpecSpecify the customization specification to be used
VAppPlaces the virtual machine within a VApp
VersionDefines the hardware version the virtual machine will be using
VMSwapfilePolicySpecify the swap file policy that is used for the virtual machine