2 Replies Latest reply on Jun 7, 2018 11:28 AM by imompero

    rolling restart of vSphere 6.5 VCSA using powercli

    imompero Enthusiast

      Any one know if there is an particular way of restarting vcenter using powercli.  And then verifying it is up before moving on to the next vcenter?  I manage 6 vcenter environments andwith a thought to myself there has to be a better way then rebooting via the appliance web gui, pinging, testing, and repeat for the next one.

       

      I know I can do it easily a "Restart-VM -VM $vcenternames -RunAsync -Confirm" But is there a smart way of doing this? Is there a way to put vcenter HA into maintenance mode using powercli? Is there a way to create a "until" vcenter 1 is up before moving on to vcenter 2?

        • 1. Re: rolling restart of vSphere 6.5 VCSA using powercli
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          First, not sure if there currently is a public API for VCSA HA. Investigating.

           

          With the following you can restart all the VCSA to which you are connected (with Connect-VIServer).

          The Connect-CisServer in the script doesn't use Credentials because I use the VICredentialDatastore.
          Give this a try

           

           

          # Make sure you are connected to all vCenters

          foreach($vc in $global:DefaultVIServers){

             $cis = Connect-CisServer -Server $vc.Name

             $shutdown = Get-CisService -Name com.vmware.appliance.shutdown

             Write-Host "Rebooting VCSA $($vc.Name)"

             $shutdown.reboot(0,'Planned VCSA reboot')


             $sPing = @{

            ComputerName = $vc.Name

            Port = 443

            WarningAction = 'SilentlyContinue'

            }


             Write-Host "Waiting for reboot to start"

             while((Test-NetConnection @sPing).TcpTestSucceeded){

            sleep 5

            }


             Write-Host "Waiting for VCSA to come online"

             while(-not (Test-NetConnection @sPing).TcpTestSucceeded){

            sleep 5

            }


             Write-Host "VCSA $($vc.Name) started"


             $cis = Connect-CisServer -Server $vc.Name -ErrorAction SilentlyContinue

             while(-not $cis){

            sleep 5

             $cis = Connect-CisServer -Server $vc.Name -ErrorAction SilentlyContinue

            }


             $health = Get-CisService -Name com.vmware.appliance.health.system

             while($health.get() -ne 'green'){

            sleep 5

            }

             Write-Host "VCSA $($vc.Name) health status green"

          }

          • 2. Re: rolling restart of vSphere 6.5 VCSA using powercli
            imompero Enthusiast

            Thanks, going to give this a try tonight!