vSphere : PowerCLI Create New VM

vSphere : PowerCLI Create New VM

The script below will semi-automate the creation of a new VM. Change the items in red to suit your environment.

$vmhost = Get-VMHost “hostname
$ds = Get-Datastore “datastore_name
$rp = get-resourcepool “pool_name

#Desired VM name

$vmname = “vm_name

New-VM -name $vmname -VMHost $vmhost -numcpu 2 -DiskMB 10240 -memoryMB 4096 -datastore $ds -guestID rhel5_64Guest -resourcepool $rp -cd -NetworkName dvPortGroup_Internal_VLAN110

To add an additional hard disk to the new VM:

Get-VM $vmname | New-HardDisk -CapacityKB (8*1gb/1024)

Alternative -guestID options:
windows7Server64Guest (2008 R2)
winNetEnterprise64Guest (2003 x64 Ent)