VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

Upgrading esxi host to 6.5 from 5.5_powercli

hi Luc D,

could you share your thoughts on following plan.

we are planning to upgrade esxi hosts to 6.5  from  5.5.

iam planning to automate this to have very less manual intervention.

foolowing is the logical plan .

a:compare each esxi host with standard version i.e 6.5.

b.if it fails then proceed to put host in maintenance mode.

c:once host is in maintenance mode install 6.5 using iso stored in one of the data store.

what power cli syntax used here.???

d:once host is upgraded to 6.5 proceed to next host.

appreciate your help

44 Replies
jvm2016
Hot Shot
Hot Shot
Jump to solution

thanks iam checking this .

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i am trying to write progress bar below each operation (specially that will take longer time ).

for example maintenance mode . so i tested only he maintence mode task. but i could not get the desired result .it sems it is not the right code.

$esxi=read-host "esxi name"

$maint=Set-VMHost -VMHost $esxi -State "Maintenance" -RunAsync

while('Running','Queued' -contains $maint.State){

    Write-Progress -Activity 'maintenance mode ' -PercentComplete $maint.PercentComplete

    $maint = Get-Task -Id $maint.Id

}

Write-Output "Task '$($maint.Description)/$($maint.Id)' for $(Get-View -Id $maint.ObjectId -Property Name | select -ExpandProperty Name) ended with status $($maint.State)"

got following error :

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect $maint might hold a client-side task, which have a different layout than server-side tasks.

Check with $maint.GetType().Name

What is in $maint?

Do a $maint | Select *


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

well first of all there is one prebuilt percent task that runs when we put host in maintenace mode usinf powercli .

however iam trying to genrealize it so that it can we run on any operations.

i tried the following way what yu asked .

not sure if it make any sense .

pastedImage_0.png

is there no direct way to check this other than this .

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You forgot the RunAsync switch on the Set-VMHost


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

oh my mistake .

so i got following output.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

For a client-side task try like this

$esxi=read-host "esxi name"

$maint=Set-VMHost -VMHost $esxi -State "Maintenance" -RunAsync

while('Running','Queued' -contains $maint.State){

    Write-Progress -Activity 'maintenance mode ' -PercentComplete $maint.PercentComplete

    sleep 2

}

Write-Output "Task '$($maint.Description)/$($maint.Id)' for $($maint.Result.Name) ended with status $($maint.State)" 


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

so below is what i am supposed to get .

pastedImage_0.png

since right now we have some issue with cluster vmotion network so it will not progress .

iam going to fix that then will proceed on this project tomorrow.

Thanks for your help .

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

hi Luc ,

Good Morning,

i modified  the script little more .

$vcenter=read-host "vcenter name"

$user=read-host "user name"

$password = read-host "password for vcenter"

$cluster=read-host "cluster to be upgradeted"

$std_version=Read-Host "what version you want to upgrade to"

$baseline_cisco= get-baseline -Name 'Cisco Custom ESXi 6.5 Upgrade'

$baseline_dell=get-baseline -name "ESXi6.5Upgrade-Dell"

#above can be different baseline also depending on the model.

connect-viserver -server $vcenter -User $user -Password $password

$hosts_cluster=get-vmhost -location $cluster

$count=$hosts_cluster.count

$count

foreach ($esxi in $hosts_cluster)

{

if ($esxi.version -ne  $std_version)

{

write-host $esxi.name  "needs to be upgraded to " $std_version

write-host "putting host" $esxi.name "in mainteneace mode"

$maint=Set-VMHost -VMHost $esxi -State "Maintenance" -RunAsync

}

#how to put progress task

while('Running','Queued' -contains $maint.State){

    Write-Progress -Activity 'maintenance mode ' -PercentComplete $maint.PercentComplete

    sleep 2

}

Write-Output "Task '$($maint.Description)/$($maint.Id)' for $($maint.Result.Name) ended with status $($maint.State)" 

if($esxi.Manufacturer -match "cisco system Inc")

{

Attach-Baseline -Entity $esxi -Baseline $baseline_cisco

}

else

{

Attach-Baseline -Entity $esxi -Baseline $baseline_dell

}

#break;

#upgrading esxi host.

$update_esxi=Update-Entity -Baseline $baseline -Entity $esxi -RunAsync

while('Running','Queued' -contains $update_esxi.State){

    Write-Progress -Activity 'upgrading host  ' -PercentComplete $update_esxi.PercentComplete

    sleep 2

}

Write-Output "Task '$($update_esxi.Description)/$($update_esxi.Id)' for $($update_esxi.Result.Name) ended with status $($update_esxi.State)"

}

i want to test this on a cluster but dont want to start the upgrade process right now .so i am thinking to add -whatif switch on maintenance mode and upgrade task .

will this handle errors or can yu suggest anything else for error handling.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The WhatIf switch is fine to see the cmdlets that would be executed, but some features like the progress bar will be difficult to simulate this way.

Moreso since you will not have a real Task object.


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i just want to check two things now to see whether host will go in maintenance mode  and will upgrade go smoothly without error .

so i checked the following code on one esxi .

and got following output .

so i have three questions here.

1:does below output ensure that host will go into maintenance mode without any issues as we put whatif switch and did not get error maintenance mode.

2:for some reasons there is error for attaching base line which is available in updatemanger .not sure why

3:how to encrypt the password while giving input at console.

pastedImage_1.png

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

adding code again

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

From the error message I would think that the baseline you are trying to use is not defined on the same vCenter as the ESXi node to which you want to attach the baseline.


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

it is defined in vcenter to which host belong to .

i can see ESXi6.5Upgrade-Dell .

also as i asked ealier will there be problem in putting to maintenance mode .  thnaks for yur response.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I notice you seem to have two baselines with the same name.

Does the Get-Baseline return one object or multiple objects?


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

could you please suggest something iam getting output repeated .

how it is happening.this is happening at all inventory level.

powercli is doubling what we see in vsphere client ..Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect you have multiple open connections.

Check what is in $global:defaultviservers


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

there were two sessions .i closed all and opened again .trying the same code again .

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

this time i got no error and got following  output.

pastedImage_0.png

since i used whatif for both maintenance mode and update-entitiy  and there is no error .

this means when i use this code during change time it will run without error or in other words what i mean to ask that  it ensures that host will go intomaintence mode and upgrade will be done without error .IS this correct??

Thanks for your response.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm not going to state that you will see no errors when removing the WhatIf switches, but it looks good.


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

0 Kudos