VMware Cloud Community
RvdNieuwendijk
Leadership
Leadership

Script to update all your hosts

I made the following script to update all our hosts. It saves me a lot of time when updating all my hosts because now I can start the script and have just to wait untill all my hosts are updated. Before I had to put a host in maintenance mode, remediate the host and exit maintenance mode. And I had to do this for all my hosts. The script asumes that you use DRS in your clusters to move the VM's when you put a host in maintenance mode:

$Baseline = Get-Baseline -TargetType host
Get-VMhost | ForEach-Object {
  Set-VMhost  -vmhost $_ -state maintenance
  Remediate-Inventory -Entity $_ -Baseline $Baseline -Confirm:$False
  Set-VMhost -vmhost $_ -state connected
}

Have fun!

Robert van den Nieuwendijk

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Tags (2)
Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

Perhaps you should mention that this will only work with cluster nodes when the DRS Automation level is set to "fully automated".

As long as there are active guests, your hosts will not enter maintenance mode.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

Luc, thanks for this extra info.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
Denjoh
Contributor
Contributor

Can you help me?

I do not understand the stages to be realized to update with update manager and powershell, a vm or several vm

My baseline is created.

Thank you in advance

Reply
0 Kudos
MartinAmaro
Expert
Expert

Hello,

Did you get a chance to downloading the software and look at the documentation?

~Martin

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful.
Reply
0 Kudos
Denjoh
Contributor
Contributor

Thank you for your answer

However, I make the update in graphic mode with update manager and the baseline created

But, i'm sorry

I am a greenhorn in powershell.

You would have the commands to be crossed (go) to make the update with the commands powershell of a vm or several vm

Have you examples

Thank you in advance

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

I see that my script got a little mangled by the forum software. I was quite new to the forum when I posted the script. Will do it better this time ;-).

$Baseline = Get-Baseline -TargetType host
Get-VMhost | ForEach-Object {
  Set-VMhost -vmhost $_ -state maintenance
  Remediate-Inventory -Entity $_ -Baseline $Baseline -Confirm:$False
  Set-VMhost -vmhost $_ -state connected
} 

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
esxi1979
Expert
Expert

$Baseline = Get-Baseline -TargetType host Get-VMhost | ForEach-Object {   Set-VMhost -vmhost $_ -state maintenance   Remediate-Inventory -Entity $_ -Baseline $Baseline -Confirm:$False   Set-VMhost -vmhost $_ -state connected } 

QQ I have below requirement :

1. On each cluster the all the hosts should be patched, one after the other.

2. Will the above run simultaneously  for all host ,( in that case it will result in outage)?

3. I want to apply only "critical & non-critical" patches only ?

4. I would like to skip host which is already patched to latest , will it do that ?

Thanks

Reply
0 Kudos