1 Reply Latest reply on Jan 23, 2020 11:41 PM by LucD

    DRS cluster - rolling reboot of esxi

    esxi1979 Hot Shot

      Hi LucD

       

      Looking for a script for - DRS cluster - rolling reboot of esxi

       

      I did see 1 script

       

       

       

      PowerCLI Script For vSphere Cluster Rolling Reboot | Infrastructure Adventures

       

      But i wanted to check if you have something too ? ( Industry standard for container orchestration is K8s, for powerli it is LucD

       

       

      Pls confirm this will work on all version of any improvemnmet since esxi 4x when you published it

       

      $clusterName = <clustername>

      $rebootMax = 2

       

       

      $targets = @{}

      $rebooting = @{}

       

       

      Get-Cluster -Name $clusterName | Get-VMHost | %{

      $targets[$_.Name] = $_

      }

      $esxNr = $targets.Count

       

       

      while($targets.Count -gt 0){

      while($rebooting.Count -le $rebootMax -and $targets.Count -gt 0){

      $waiting = $targets.Values | %{$_}

      $waiting | Select -First 1 | %{

      Set-VMHost -VMHost $_ -State "Maintenance" | Restart-VMHost -RunAsync -Confirm:$false -WhatIf

      $targets.Remove($_.Name)

      $rebooting[$_.Name] = $_

      }

      }

      sleep 10

      while($rebooting.Count -eq $rebootMax -or ($rebooting.Count -ne 0 -and $targets.Count -eq 0)){

      $active = $rebooting.Values | %{$_}

      $active | %{

      $esx = $_

      if($esx.State -eq "Maintenance"){

      Set-VMHost -VMHost $esx -State "Connected"

      $rebooting.Remove($esx.Name)

      }

      }

      sleep 10

      }

      }

        • 1. Re: DRS cluster - rolling reboot of esxi
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          I do see a potential issue with the sleep 10.

          If an ESXi node is not back again within those 10 seconds, your subsequent Set-VMHost might fail.

           

          I would add a loop to wait for the rebooted ESXi node to be powered on again, before continuing with the Set-VMHost.

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz