Hi,
I need to perform a major maintenance of an infrastructure containing roughly 100 Vms.
I have to poweroff all the Vms, as quickly as possible but also as safe as possible.
Firstly I'm writing a script to shutdown all the vm, something basic like that :
Get-Cluster -Name $clusterName | Get-VM |
Where-Object {$_.Powerstate -eq "poweredon"} |
Shutdown-VMGuest -Confirm:$false
But I'm just curious if the shutdown will be syncronous or asyncrous ?
I think the shutdown will be machine per machine but I can't find the information for sure.
The problem is if it's the case, the shutdown process will take time.
What is the best solution to shutdown quickly 100 Vms whitout taking any risk ?
Bets regards
As the help for the Stop-VMGuest cmdlet states "This cmdlet issues a command to the guest operating system asking it to prepare for a shutdown operation. Returns immediately and does not wait for the guest operating system to complete the operation."
So it is async.
One way of controlling this is to use a loop with a While-clause, that keeps checking till all the targetted VMs are actually powered off.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something like this for example
Get-Cluster -Name MyCluster | Get-VM | Stop-VMGuest -Confirm:$false
while((Get-Cluster -Name MyCluster | Get-VM).PowerState -contains 'PoweredOn'){
sleep 5
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your quick answer !
Do you have any details about the number of shutdown Vmware can perform simultaneously without having any problem ?
Do you think I should add something to the script to perform the VMs shutdown 10 by 10 for example or Vmware is able to handle 100 VMs whitout risks ?
Thanks in advance
I'm not aware if there is a maximum of VMs that you can shutdown.
But to minimise the load on your system, you could do the shutdown in batches.
The following sample shuts down VMs 5 at the time.
$maxVM = 5
$vms = Get-Cluster -Name MyCluster | Get-VM
1..($vms.Count/$maxVM) | ForEach-Object -Process {
$index = ($_ - 1) * $maxVM
$subVMs = $vms[$index..($index + $maxVM - 1)]
Stop-VM -VM $subVMs -Confirm:$false
while((Get-VM -Name $subVMs.Name).PowerState -contains 'PoweredOn'){
sleep 5
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference