Create a VM and do some configuration with PowerCLI
Fri-2013-11-08 1 Comment
Like so many others, I’ve been trying to up my PowerCLI skills lately. I do this to make my life and that of my colleagues a bit easier and to get the skills needed to up my certification to the VCAP level 🙂
Here’s some code to create a 64-bit Oracle Enterprise Linux VM with virtual hardware version 9 and without floppy. I’ll try to update this post as more settings must or can be made.
Create the VM with 7 disks.
$name = “MyVMName”
New-VM -VMHost MyESXiHost -CD -Name $name -MemoryMB 16384 -NumCPU 1 -Version v9 -GuestId oracleLinux64Guest -Datastore VMFS3 -DiskGB 10,20,30,200,200,200,10 -DiskStorageFormat Thin
Some settings which are annoying to do with a mouse and also easily forgotten
$vm = Get-VM $name
New-AdvancedSetting -Entity $vm -Name ‘vcpu.hotadd’ -Value ‘true’ -Confirm:$false
New-AdvancedSetting -Entity $vm -Name ‘mem.hotadd’ -Value ‘true’ -Confirm:$false
New-AdvancedSetting -Entity $vm -Name ‘svga.autodetect’ -Value ‘true’ -Confirm:$false
This is some code to do the same if the settings have already been configured
$vm | Get-AdvancedSetting -Name ‘vcpu.hotadd’ | Set-AdvancedSetting -Value ‘true’ -Confirm:$false
$vm | Get-AdvancedSetting -Name ‘mem.hotadd’ | Set-AdvancedSetting -Value ‘true’ -Confirm:$false
$vm | Get-AdvancedSetting -Name ‘svga.autodetect’ | Set-AdvancedSetting -Value ‘true’ -Confirm:$false
Change NIC and SCSI controller type
Get-VM $vm | Get-CDDrive | Set-CDDrive -ISOPath “[VMFS1] ISO\oel_6.4_boot.iso” -StartConnected $true -Confirm:$false
Get-VM $vm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName Vlan126 -Confirm:$False
Get-VM $vm | Get-NetworkAdapter | Set-NetworkAdapter -Type VMXNet3 -Confirm:$False
Get-VM $vm | Get-ScsiController | Set-ScsiController -Type ParaVirtual
Add the last 4 disks to a seperate SCSCI controller
$disks = Get-Harddisk -VM $vm | Select -Last 4
New-ScsiController -Type ParaVirtual -Harddisk $disks
Start the VM
Start-VM $vm
That’s it for now. Comments are welcome.