################
#
# snappy.ps1
# This will create snapshots of systems in a previously used CSV.
# You will need to setup some variables if desired
#
# Create by Ryan Kovar/16DEC2011
#################################
add-pssnapin VMware.VimAutomation.Core
#Your Vcenter or ESX host
$VIserver = "YOUR SERVER"
#Your list of systems
$vms = Import-CSV .\YOUR.CSV
#Name of the snapshot
$NAME = "SNAP"
##############################
Connect-VIserver $VIserver
foreach ($vm in $vms){
#Stops all the VM's just incase they were started
Stop-VM -VM (Get-VM -Name $vm.name) -Confirm:$false
get-VM $vm.name | New-Snapshot -Name $NAME
}
Friday, December 16, 2011
For automating Snapshots
And here is another one for automating snapshots:
Creating New VM's with PowerCLI
Really this is a placeholder for a longer post but the below is a powerCLI script that will create a new vm from a templates using a CSV file for input. Then the script starts them so that they can run their MSFT Sysprep
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
################
#
# 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
}
Subscribe to:
Posts (Atom)