---------------------------------------------------------------------------------------------------------------
################
#
# Create_new_VMs.ps1
# This scripts allows for automated creation and then powerdown of machines
# You will need to create a CSV file to use for input. Please see
# format below. When the script executes it will need a template to use. Then it will read the CSV
# to input the computer names and which customization to use. Then after the machines are created, it
# starts the machines (after a 30 second break). The machines should then boot up and shortly begin
# running sysprep. You will also need to set variables listed in the script for your specific environment
#
# file.CSV format:
# Name,Customization
# Test1,Test1
# Test2.Test2
## Create by Ryan Kovar/16DEC2011
#################################
#Set these variables below for your environment.
#Your Vcenter or ESX host
$VIserver = "YOUR BOX"
#Your list of systems and OScustimizations. Please note this can be extended. Review the Vsphere PowerCLI Reference guide for more help. Enter in whatever path you want. This one executes locally
$vms = Import-CSV .\file.csv
#This is which box you wish to put your hosts on
$VMhost = "YOUR HOST"
#Which resource pool
$ResourcePool = "YOUR POOL"
#This will ask when you execute for which template. You could also set this as a static Variable like above
$template = Read-Host "Please enter which Virtual Template you wish to use: "
########################
Connect-VIserver $VIserver
foreach ($vm in $vms){
$OSCustomization = Get-OSCustomizationSpec $vm.customization
New-VM -Name $vm.name -OSCustomizationSpec $OSCustomization -Template $template -VMHost $VMhost -ResourcePool $ResourcePool
}
foreach ($vm in $vms){
sleep 30
Start-VM -VM (get-VM -Name $vm.name) -RunAsync
}
0 comments:
Post a Comment