Wednesday, April 8, 2009

Deploying Virtual Machines from PowerShell (VMware)

The below steps will allow you to deploy virtual machines based off a template, to a designated host and data store.

Requirements:
VMware VIToolKit
Microsoft Powershell

Steps:

1) Connect to your Virtual Center server using: Connect-VIServer
a) This will prompt you for the server name and password; once connected you can proceed
2) Enter all machines to be created in to an array: $array = "Machine1","Machine2","Machine3" (and so forth)
3) Define the host where the template resides: $host = "ESX Server Name (must be in DNS)"
4) Define the template to use for deploying these machines: $template = "Template Name"
5) Define the Data Store where the machines will be deployed to: $datastore = "Data Store Name"
5) Now to actually deploy the machines:

foreach ($vm in $array)
{
$vm=New-VM -Name $vm -Template $template -Host $host1 -Datastore $datastore
}



Now the machines will deploy one at a time to the defined server. You can specify resource pools if you deseire or you can move the machines once they are fully deployed.