# Connect to vSphere
Connect-VIServer -Server sol.xxxx.co.uk -User
administrator@vsphere.local -Password xxxx?
# Define VM parameters
$vmName = "TestVM111"
$datastore = "Crucial SSD"
$network = "VM Network"
$vmHost = "192.168.0.253"
$vmFolder = "Test"
$isofile = "[1.5TB HDD] ISO/SERVER_EVAL_x64FRE_en-us.iso"
$controllerType = "VirtualLsiLogicSAS"
$OS = "windows9Server64Guest"
# Create new VM
$vmSpec = New-VM -Name $vmName -Datastore $datastore -Location $vmFolder -cd -DiskGB 40 -MemoryGB 4 -NumCPU 2 -NetworkName $network -VMHost $vmHost -GuestId $OS
# Mount the ISO from datastore
get-cddrive -VM $vmName | Set-CDDrive -IsoPath $isofile –StartConnected $True -confirm:$false
# Set SCSI controller
$vm = Get-VM -Name $vmName
$disks = Get-HardDisk -VM $vm
foreach ($disk in $disks) {
$controller = Get-ScsiController -HardDisk $disk
Set-ScsiController -ScsiController $controller -Type $controllerType
}
#Boot Options Firmware EFI
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.Firmware = [VMware.Vim.GuestOsDescriptorFirmwareType]::efi
$vm.ExtensionData.ReconfigVM($spec)
# Modify VM settings to enable automatic boot from ISO
$bootOrder = New-Object VMware.Vim.VirtualMachineBootOptionsBootableDevice[] (1)
$bootOrder[0] = New-Object VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice
$vm.ExtensionData.Config.BootOptions.BootOrder = $bootOrder
# Power on VM
Start-VM -VM $vmSpec