You never know when you’ll need to script something and PowerCLI gives you the tools to do it. I decided to see if I could script some of the VMware Update Manager (VUM) tasks while I was reviewing section 5.2 of the VCAP5-DCA Beta Blueprint and found that the procedures were quite easy. My next thought was, “Why would I want to script this when I can use the GUI, and on top of that I can schedule scans and remediation already?” My answer was, “You never know.” Who knows when you’ll need to use the PowerCLI to accomplish a task. Maybe, you’re scripting something so someone else can run it without really knowing how to perform the task, or you’re trying to get a report, or who knows.
Here is a basic procedure to scan and remediate some ESX hosts.
You must have PowerCLI and the VUM cmdlets installed before you can run any of these commands.
First, we’ll create a patch baseline. In this case the patch baseline will get dynamic updates that are for ESXi hosts, only critical VMware Updates, and released after May 1st 2012. We’ve named the baseline “PowerCLIBaseline.”
[sourcecode language=”PowerShell”] new-patchbaseline -dynamic -name PowerCLIBaseline -description "PowerCLI Baseline Example -TargetType Host -SearchPatchVendor *VMware* -SearchPatchSeverity critical -SearchPatchStartDate 5.1.2012 [/sourcecode]
Next, we want to attach our newly created baseline to an object. In my example we’re attaching it to the Prod Cluster, but it could be attached to a virtual machine, a host, or a folder just like it could be from the GUI.
[sourcecode language=”PowerShell”] get-baseline PowerCLIBaseline | attach-baseline -Entity "Prod Cluster" [/sourcecode]
[sourcecode language=”PowerShell”] Scan-inventory -entity "Prod Cluster" [/sourcecode]
To show that you can run this on objects other than a Cluster, we’ll update only one of the two hosts. We remediate hosts 192.168.160.30.
[sourcecode language=”PowerShell”] get-baseline -name PowerCLIBaseline | Remediate-inventory -entity 192.168.160.30 [/sourcecode]