Hi,
I've 2 esx hosts 5.5 setup as vSphere 5.5 in HA, on one of them is running vCenter as virtual appliance, but assumed that I don't know on which of them.
I've created the script in PowerShell, that shutdown vCenter Server Appliance, copy it as ova file and then started vCenter.
Script runs on Windows 2008 Server, which is separate, non virtual machine.
When I run it manually, it work as I want.
When I schedule the script, it shut down vCenter, copy it as ova file, BUT DOESN'T START vCenter.
Would anybody give some tip where could be the mistake or some couses of this behaviour?
Regards,
Mariusz
Here are the script:
(...)
$vESXiHosts = "172.xxx.xxx.xxx","172.xxx.xxx.yyy"
$vCenterName = "vCenter 5.5 Server Appliance"
ForEach ($esx in $vESXiHosts)
{
$vHost_connected = $True
$vCenter_founded = $False
try { Connect-viserver $esx -user $vESXiUser -password $vESXiPwd -WarningAction 0 -ErrorAction Stop | Out-Null }
catch { $vHost_connected = $False }
if ($vHost_connected)
{
$VM_vCenter = Get-VM | Where {$_.Name -eq $vCenterName}
if ($VM_vCenter)
{
$vCenter_founded = $True
if ($VM_vCenter.PowerState -eq "PoweredOn")
{
Shutdown-VMGuest $VM_vCenter -Confirm:$false
$VM_vCenter | ForEach {
do
{
$VM_vCenter = Get-VM $_
$pwr = $VM_vCenter.PowerState
if ($pwr -ne "PoweredOff")
{
Write-Host "Waiting for $VM_vCenter to shutdown, the status is $pwr"
Sleep 10
$licznik += 10
}
else
{
Write-Host "$VM_vCenter is $pwr"
}
} until (($VM_vCenter.PowerState -eq "PoweredOff") -or ($licznik > 300))
}
}
Sleep 120 #I wailt 2 min. to be sure that vCenter closed on 100% 🙂
$status = "OK."
try { Export-VApp -Destination $backupdir -VM $VM_vCenter -Force -ErrorAction Stop }
catch { $status = "ERROR!" }
if ($VM_vCenter.PowerState -eq "PoweredOff")
{
Start-VM $VM_vCenter -Confirm:$false
}
}
}
if ($vCenter_founded) { break }
}
if ($global:DefaultVIServers.Count -gt 0)
{
try { Disconnect-VIServer * -Force -Confirm:$false }
catch { }
}