VMware Cloud Community
imompero
Enthusiast
Enthusiast
Jump to solution

rolling restart of vSphere 6.5 VCSA using powercli

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?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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"

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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"

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
imompero
Enthusiast
Enthusiast
Jump to solution

Thanks, going to give this a try tonight!

0 Kudos