VMware Cloud Community
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

Upgrade VCSA with Update Manager

Hi

So I'm trying to upgrade vcenter via powershell commands

and I've found this module 'VMware.Community.VCSA.Update' which is very helpful.

but the script ends before the vcenter is actually upgraded.

so I made this:

Start-VCSAUpdateStageandInstall -Version $vcVersion -SSODomainPass $vCPW -Verbose

$sysAPI = Get-CisService -Name 'com.vmware.appliance.update' -Server $vCenter
$rslts = $sysAPI.get()
$sumRslts = [pscustomobject] @{
    "Progress" = $rslts.task.progress
}
$sumRslts
Write-Host "Progress Completed" $sumRslts.Progress.completed "out of " $sumRslts.Progress.total -ForegroundColor Yellow 

I want the script to wait until the vcenter is fully upgraded, and also I want to print out every time the $sumRslts.Progress.completed is updated.

my meaning is, for example the first time I run this method it prints out 

"Progress Completed 0 out of 245" 
and the script is done, but the vcenter still in the upgrade process, and if I run only this line again

Write-Host "Progress Completed" $sumRslts.Progress.completed "out of " $sumRslts.Progress.total -ForegroundColor Yellow 

 I get print out of the number it got at that time I ran that line. for example "Progress Completed 15 out of 245"

how can I make it to print out every time the $sumRslts.Progress.completed is updated, and make it all in "while" loop, until the vcenter completely upgraded 100%, and at the end i'll print out "Progress Completed 245 out of 245" 


Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You will have to find out when the connection breaks.
Perhaps by using a Try-Catch (provided you get a terminating exception when the current connection breaks?).

Then do a loop until the service is back ( a good test could be waiting till the new Connect-CisServer succeeds).

Once done, you can run an identical loop as you ran before, but under the new connection to the Cis service.


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

View solution in original post

36 Replies
LucD
Leadership
Leadership
Jump to solution

The easiest way is to run that 

$sysAPI.get()

in a loop until the process is completed.
Since the object returned by that method is not updated dynamically, you can't use an event registry afaik (like you can for some .NET objects).


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

0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

I do run that, if you can see in line 4 I got 

$rslts = $sysAPI.get()

and then I call "Progress" = $rslts.task.progress

I'm trying to do a while loop for that. so every update of that status will print out. and the script will not finish until its all completed.

tried this 

$insUpg = Start-VCSAUpdateStageandInstall -Version $vcVersion -SSODomainPass $vCPW -Verbose
$sysAPI = Get-CisService -Name 'com.vmware.appliance.update' -Server $vCenter
$rslts = $sysAPI.get()
$sumRslts = [pscustomobject] @{
    "Progress" = $rslts.task.progress
}
$sumRslts
while ($insUpg) {
    $rslts = $sysAPI.get()
    $sumRslts = [pscustomobject] @{
        "Progress" = $rslts.task.progress
    }
    Write-Host "Progress Completed" $sumRslts.Progress.completed "out of " $sumRslts.Progress.total -ForegroundColor Yellow 
}

 but it just giving me thousands of lines with this:

Progress Completed 34 out of  245
Progress Completed 34 out of  245
Progress Completed 34 out of  245
Progress Completed 34 out of  245
Progress Completed 34 out of  245
Progress Completed 34 out of  245
Progress Completed 34 out of  245
Progress Completed 34 out of  245
Progress Completed 34 out of  245
Progress Completed 34 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 35 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 36 out of  245
Progress Completed 37 out of  245
Progress Completed 37 out of  245
Progress Completed 37 out of  245
Progress Completed 37 out of  245
Progress Completed 37 out of  245
Progress Completed 37 out of  245
Progress Completed 37 out of  245
Progress Completed 37 out of  245
Progress Completed 37 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245
Progress Completed 38 out of  245

 

how can I make it only to update while the "Completed" one is updated... so it will be eventually like this:

Progress Completed 34 out of  245
Progress Completed 35 out of  245
Progress Completed 36 out of  245
Progress Completed 37 out of  245
Progress Completed 38 out of  245

 

and the 'while' loop will finish when it got to fully upgraded 100%.

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I mean something like this

$insUpg = Start-VCSAUpdateStageandInstall -Version $vcVersion -SSODomainPass $vCPW -Verbose
$sysAPI = Get-CisService -Name 'com.vmware.appliance.update' -Server $vCenter

$oldNrTask = 0

while ($insUpg) {
  $rslts = $sysAPI.get()
  if ($oldNrTask -ne $rslts.task.progress) {
    $sumRslts = [pscustomobject] @{
      "Progress" = $rslts.task.progress
    }
    Write-Host "Progress Completed $($sumRslts.Progress.completed) out of  $($sumRslts.Progress.total)" -ForegroundColor Yellow
    $oldNrTask = $rslts.task.progress     
  }
}


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

0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

thanks, but it still showing same as before 

alot of outputs instead of only the updated output each time 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Strange, it should only print a message when the current task has a different number


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

0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

from the script yes it looks like it should output when it has different number

but unfortunately it prints out all the time not only when change numbers

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then you will have to use debugger and find out why that IF doesn't limit the output.


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

0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

sadly even on debugger I didnt see any "issue" tried to step in the if statement, and it just getting it every time like it should.

I'm lost here... dont know what else to check or do.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sometimes it is helpful to start from scratch.

Stop/start your PowerShell/PowerCLI session.
Make sure the code is actually the code you are intending to run that is running.
When comparing strings look at what is in the strings character by character (hex view), some characters are not displayed but can make a difference when a comparison is made.
Be very wary about casting, and know the rules, when comparing objects of different types, i.e. int vs string.

Btw, which debugger are you using?
I strongly recommend Visual Studio Code instead of the ISE.


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

0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

sadly I'm using the ISE debug, since I can run PS scripts only on terminal server on VMWare sites. 

and cannot install there Visual Studio Code.

and also can't run the scripts outside the terminal on the hosts\vc so yeah only able to do with ISE

 

I tried to stop\start the session from scratch, and also tried to run only the part of the install upgrade and the if statement

again sadly can't see anything in the debug. atleast nothing that I can see as an issue for the statement that causing that.

anyway I guess i'll stick with that... don't know if it will cause any issues to the script itself. 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

What could help, is writing all involved variables to a file, which you can open in hex view (for example with Notepad++).
Sometimes a Transcript log can help as well


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

0 Kudos
knikolov
VMware Employee
VMware Employee
Jump to solution

If you want just one message that just updates itself you can replace Write-Host with Write-Progress like this:

Write-Progress -Activity "VCSA Update" -Status "Progress Completed $($sumRslts.Progress.completed) out of  $($sumRslts.Progress.total)" -PercentComplete ($sumRslts.Progress.completed/$sumRslts.Progress.total*100)
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

for some reason the divide got error, but its even better for me, I do not want it to show in percentage, I want to see the full number of 
completed out of full number of the total amount.

so this is great thanks it worked!

0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

ok a new issue popped up now.

when its getting to some point of the upgrade, obviously it stopping the services (around 70% of the installation progress I think)

and the script just goes crazy with lots of errors lines like this: 

A server error occurred: 'com.vmware.vapi.std.errors.service_unavailable': Service unavailable. (Server error id: 'com.vmware.vapi.endpoint.cis.ServiceUnavailable'). Check $Error[0].Exception.ServerError for more details.

 and like this:

Unexpected character encountered while parsing value: n. Path '', line 0, position 0..

 

obviously these errors occurred since the services of the vcenter stopped, but then when it came back, in VAMI the upgrade continued normally, but the script stuck in loop of these issues.

could you help me out with continue of the script that will wait until the services comes back and then continue with the script? 

for example it stuck on:

"VCSA Update. Progress Completed 117 out of 167." 

and meanwhile the installation in VAMI went from 70% (which was 'stopping services') to 88% (which is 'converting data as part of post install') 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You will have to try and connect to the CIS Service in a loop, and then do the Get-CisService for 'com.vmware.appliance.update' again, and call the get method.
Not sure if that call will pick up the running update task though.
You will have to try this out.


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

Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

HI, 

yes I already have the get cisservices of that and i'm calling it's get method too.

but I'm trying to loop it in a while loop, only I'm not sure how to continue when the loop breaks as the services stops

how should I make the while loop to actually wait for the services to come back up?

this is what I have: 

$sysAPI = Get-CisService -Name 'com.vmware.appliance.update' -Server $vCenter
$oldNrTask = 0
while ($insUpg) {
    $rslts = $sysAPI.get()
    if ($oldNrTask -ne $rslts.task.progress) {
        $sumRslts = [pscustomobject] @{
            "Progress" = $rslts.task.progress
        }
        while ($rslts) {
            Write-Progress -Activity "VCSA Update" -Status "Progress Completed $($sumRslts.Progress.completed) out of  $($sumRslts.Progress.total)"
            $oldNrTask = $rslts.task.progress
        }
    }
}

is that the correct way to do a while loop for a new get method? 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Aren't you doing a Connect-CisServer as well?
I assume the existing connection is broken after the service stops, and you will have to connect again.


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

0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

oh ok I see, but when to connect the second time?

before the second while loop so the while($rslts) will try again as it connecting every time the CisServer ? 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You will have to find out when the connection breaks.
Perhaps by using a Try-Catch (provided you get a terminating exception when the current connection breaks?).

Then do a loop until the service is back ( a good test could be waiting till the new Connect-CisServer succeeds).

Once done, you can run an identical loop as you ran before, but under the new connection to the Cis service.


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