Created
November 7, 2019 15:36
-
-
Save manualbashing/4e59ef50d4aed7f619e4c186488e8a6b to your computer and use it in GitHub Desktop.
[Restart all Hosts in Cluster without DRS] Restart all #ESXi Hosts in a cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $VerbosePreference = 'Continue' | |
| foreach ($vmh in (Get-VmHost)) | |
| { | |
| Write-Verbose "Move all VMs from $vm to $targetHost" | |
| $vmh | Get-VM | Move-VM -Destination $targetVMHost | |
| Write-Verbose "Send $vmh to Maintenance mode" | |
| $vmh | Set-VMHost -State Maintenance | |
| Write-Verbose "Restart $vmh" | |
| $vmh | Restart-VMHost -Confirm:0 | |
| while((Get-vmhost $vmh).ConnectionState -eq 'NotResponding') { sleep -Seconds 10 } | |
| Write-Verbose "$vmh entered state $($vmh.ConnectionState)" | |
| $vmh | Set-VMHost -State Connected | |
| while((Get-vmhost $vmh).ConnectionState -ne 'Connected') { sleep -Seconds 10 } | |
| Write-Verbose "$vmh entered state $($vmh.ConnectionState)" | |
| $targetVMHost = $vmh | |
| Start-Sleep -Seconds 60 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment