VMware Cloud Community
admin
Immortal
Immortal

Script to update hosts when using Auto Deploy(Stateless ESXi)

The attached script demonstrates how to automate host updates when using the Auto Deploy feature in vSphere 5.  Here's an excerpt from the comment at the top (take a look at the script for more details.)

# This script will help automate patching/updating large numbers of

# stateless hosts.  On the first invocation of the script, specify
# a cluster to remediate, the new image profile, and the old image mapping
# rule.  The script will update the deploy rule to use the new image profile.
# The script will then loop through all the hosts in the cluster,
# put them in maintenance mode, and reboot once the VMs are migrated off
# via DRS.  On subsequent invocations of the script, you can specify
# just the cluster (this assumes you have multiple clusters that leverage
# the same image profile deploy rule in Auto Deploy)

Here's an example of what using this script might look like:

Connect-VIServer MyVcHostName

Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml

Get-EsxImageProfile

# Scan through the list and pick the one you want

Get-DeployRule

# Note the name of your image profile assignment rule

.\ad-update.ps1 MyClusterName ESXi-5.0.0-XXXXXX-no-tools MyDeployRule

# Replace XXXXXX with the build number, or alternative image profile name as the second argument

You can also use your own custom image profiles by leveraging the image builder cmdlets.

Daniel

0 Kudos
3 Replies
alanrenouf
VMware Employee
VMware Employee

Awesome script Daniel.

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
RightSolution
Contributor
Contributor

Hi,

Great job on this script. One quesiton I have, Is it possible to use $OEMString for identifying hosts instead of MAC or BIOS UUID?

UCS can supply ESX service Profile name via $OEMString that can be used to associate ESX image.

I would like to attach answer file to ESX UCS service Profile name $OEMString instead of MAC or BIOS UUID.

Much appreciated!

Eugene

0 Kudos
ep4p
Enthusiast
Enthusiast

Hello,

Script is cool unfortunately all my hosts are not coming back mentioning that they are running the desired image. And if I run the Test-Deplo yRuleSetCompliance at any host it comes back as compliant.

Found out that if I reboot the hosts before running your script all works well.

Any clue why Test-DeployRuleSetCompliance does not verify compliance correct or is there any way to enforce this test? What gets changed after a reboot so this command does the job?

Thanks.

0 Kudos