A new ESXi 6.5 patch came out today:
And I wanted to upgrade my whole lab environment to it and I haven’t set up auto-deploy or update manager yet (I plan to, making all of this much easier to manage). So I wrote a quick and dirty PowerCLI script that updates to the latest patch and if the host doesn’t have any VMs on it, puts it into maintenance mode and reboots it. I will reboot the other ones as needed.
So short, not really even worth throwing on GitHub, but I might make it cleaner, and smarter at some point and put it there.
Some notes on this script:
- Use are your own danger! It does reboot hosts, though only ones with no VMs. There is no error checking etc., etc.
- I am using the standard build, so if you have special build this won’t be the exact process.
$esxihosts = get-vmhost
foreach ($esxi in $esxihosts)
$esxcli = $esxi |get-esxcli -v2
$argsInstall = $esxcli.software.profile.install.createargs()
$argsInstall.depot = "https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml"
$argsInstall.profile = "ESXi-6.5.0-20171204001-standard"
$vms = $esxi |get-vm
if ($vms.count -eq 0)
$esxi | set-vmhost -State Maintenance
$esxi | Restart-VMHost -RunAsync -Confirm:$false