A blog that focuses on automating system administration tasks for Linux, Windows, and VMware ESX
Sorry for the delay in posting this week. I had out-of-town guests in all weekend so everything has been turned upside down. I would like to continue from last week and show how easy it is to create a new virtual machine with Powershell. Again you'll need the VMware Powershell management Snap-in before you have access to these commands.
To Create a Virtual Machine, you need to do the following:
1. Connect to your Virtual Center server -
- $vc = Get-VIServer -Server "vc.example.com"
2. Connect to the ESX Host where you want to create the VM -
- $esx = Get-VMHost -Server $vc -Name "esx.example.com"
3. Create the virtual machine -
- $vm = New-VM $esx
- This will create a VM with a 4GB hard drive and 256MB of RAM.
- The network will be the first Network Label sorted alphabetically
4. If you want, you can specify options while you are creating the VM or you can use the Set-VM to modify the VM's specifications.
- Set-VM $vm -MemoryMB 2048 -NumCPU 4 -Network "Local Lan"
- Proceed with update of the following parameters of virtual machine with name 'blah'?
New MemoryMB: 2048MB
New NumCPU: 4
New Networks: LAN-1,
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
I tried to create a new VM from a template with the following steps, but I continually got an error while doing so. I guess this just goes to show that VMware is still developing this code and it has some ways to go.
1. Get all templates that VC knows about
- $t = Get-Templates -Server $vc
2. Create new virtual machine from the first template
- $vm = New-VM -Host $y -Template $t[0]
- cmdlet New-VM at command pipeline position 1
Supply values for the following parameters:
Name: blah2
New-VM : The operation for the entity vm-3179 failed with the following message: "A specified parameter was not correct
If someone could show me what I am doing wrong, that would be great.
Labels: vmware powershell