So today marked the release of vSphere 6.0 U2. This is pretty cool because it adds the vSphere Host Web Client. A much-needed upgrade if you speak to administrators of a vSphere environment. I have a small lab of around 16 hosts. It forms my miniature lab that allows me to test and scale NSX deployments and use-cases. I am in the midst of writing the book and wanted to minimise the time taken to update. This environment does not use VMware Update Manager so I have dallied with my new love, PowerCLI.
The following script does not consider or take into consideration the workloads. My management cluster along with test applications mean nothing to me. If you are to use this then do not use -force or -confirm:$false. Do not stop VM’s either – let vMotion and DRS do the work!
So after downloading the latest vSphere update ZIP to the cluster data store the following code is run.
$datastorename = "mgt-ds01" $clustername = "Management" $hosts = get-cluster $ClusterName | get-vmhost $hosts | get-vm | stop-vm -confirm:$false $hosts | set-vmhost -state "maintenance" -confirm:$false $hosts | Install-VMHostPatch -HostPath /vmfs/volumes/$datastorename/60u2/metadata.zip $hosts | restart-vmhost -force -confirm:$false $hosts | set-vmhost -state "Connected" -confirm:$false $hosts | get-vm | start-vm
The two environment variables outline the cluster datastore and the cluster name. The order of operations are as follows:
- Return all host within defined cluster and store it in $hosts
- Get all VMs across all hosts in cluster and hard stop without confirmation
- Set all hosts within cluster to go into maintenance mode
- Install the host patch from the datastore location defined
- Force restart all hosts
- Reconnect hosts out of maintenance mode
- Restart VMs on hosts within cluster
Get the latest info on vSphere 6.0 here
vSphere 6.0 U2 Release Notes: http://vmw.re/1R2EAdH
Download: http://vmw.re/1R2EClQ
One thought on “Use PowerCLI to upgrade vSphere”