If you have a list of vm's and you need it to be powered on, the script below will help you do that. To give the storage system air to breathe and not cause a boot storm, it powers on a VM every 2 seconds and waits 5 minutes after ever 50 VM is powered on.
Import-Module vmware.vimautomation.core
Remove-Variable * -ErrorAction SilentlyContinue
$vcenter = "hostname of vCenter or ESX host"
connect-viserver $vcenter
$count = 0
$csvfile = import-csv "Path to csv file"
foreach($vm in $csvfile)
{
$vm_info = Get-VM -Name $vm.VMName #VMName refers to column header in the csv file.
if ($vm_info.PowerState -eq "PoweredOff")
{
Write-Host "Powering on "$vm_info.Name
$poweron = Get-VM $vm_info.Name | Start-VM -Confirm:$false
Sleep 2 #power on a vm every 2 seconds.
$count++
if($count -eq 50) #powers on 50 vm's then waits for 5 minutes for storage to breathe.
{
Sleep 300
$count = 0
}
}
}
No comments:
Post a Comment
Thank you for your comment.