Skip to content

Instantly share code, notes, and snippets.

@manualbashing
Created November 7, 2019 15:36
Show Gist options
  • Select an option

  • Save manualbashing/4e59ef50d4aed7f619e4c186488e8a6b to your computer and use it in GitHub Desktop.

Select an option

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
$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