Saturday, February 11, 2012

Create VMs from Template - PowerCLI

add-pssnapin VMware.VimAutomation.Core
Connect-VIServer 1751 -User administrator -Password Password
$global:location = "Atlas-Cluster"
$global:datastore = "Atlas-NTNX-datastore"
$global:sourceVM = @("Atlas_Windows_Template")
$global:testIterations = 10
for($i=1; $i -le $global:testIterations; $i++){
new-vm -Name WinDowsAtlas$i -VMhost 170 -Template Atlas_Windows_Template -Datastore Atlas-NTNX-datastore }
$global:testIterations = 20
for($i=11; $i -le $global:testIterations; $i++){
new-vm -Name WinDowsAtlas31$i -VMhost 171 -Template Atlas_Windows_Template -Datastore Atlas-NTNX-datastore }
$global:testIterations = 30
for($i=21; $i -le $global:testIterations; $i++){
new-vm -Name WinDowsAtlas31$i -VMhost 172 -Template Atlas_Windows_Template -Datastore Atlas-NTNX-datastore }
$global:testIterations = 40
for($i=31; $i -le $global:testIterations; $i++){
new-vm -Name WinDowsAtlas31$i -VMhost 173 -Template Atlas_Windows_Template -Datastore Atlas-NTNX-datastore }
get-VM WinDows*|Start-VM

get-VMHost ip_Addr|  get-VM Windows7-*| where {$_.'PowerState' -eq "PoweredOff"} | Start-VM -RunAsync
 get-VM Windows7-*| where {$_.'PowerState' -eq "Suspended"} |Start-VM -RunAsync -Confirm:$false