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?
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
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
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
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
Thanks, going to give this a try tonight!