I’m always amazed of what you can do with PowerCLI.
Actually I’m having version 4.1 of vCenter/vSphere
I’m using complete PowerCLI script to configure freshly installed vSphere. I was configuring everything but the last patches.
VMware released for some times already a VMware Update Manager PowerCLI. It needs to be installed in addition of the PowerCLI.
You can download the Update Manager PowerCLI installer package from the product landing page at https://www.vmware.com/support/developer/ps-libs/vumps
Beware of downloading the same release than the one you are using on your infrastructure.
I tried the release 5.0 against my 4.1 infra and it didn’t work at all…
I won’t put my vSphere hosts’ configuration script in this post but I’ve made a dedicated one for VUM PowerCLI.
Okay, it does what you can already do with the vSphere client but it includes the necessary cmdlets to integrate them into any script you like.
I made this script:
In the script you have to change the credential used to connect to the vCenter server, set the correct vCenter address. You can also specify the Datacenter in which you want to work with.
The first thing this script does is to verify that the VUM’s snapin is loaded. If it is not the case the script exits.
When you are ready to go, the script will give you the list of ever hosts which are either connected or in maintenance.
Once the host selected the script will ask if you want to download the last patches.
Then the host will be scanned. After the compliance status is verified. If no baseline is somehow attached to the host, the script exits.
Only the baselines of type “patch” which are not compliant with the hosts are taken into considerations and will be remediating.
As I said earlier this code can be easily integrated in a another script