In the course of writing articles covering the VCAP-DCA objectives, I’ve used a number of examples of how PowerCLI can be used instead of carrying out tasks using the vSphere client. I’m certainly no expert in PowerCLI, but have been using it increasingly to automate certain tasks. It can be a great time saver when it comes to repetitive tasks such as creating portgroups on standard vSwitches, or making changes to groups of virtual machines.
One of the problems you face when new to PowerCLI is knowing what parameters and attributes to set when running a cmdlet. Whilst you can get help on a particular cmdlet by using the ‘get-help’ cmdlet, it doesn’t always give you all the information you need:
For example, the above image shows the help information for the ‘new-cluster’ cmdlet. Whilst it shows that ‘-DRSAutomationMode’, for example, is a parameter that can be set, it doesn’t tell you what the possible choices are (e.g Disabled, FullyAutomated) etc. This is where the ‘show-command’ cmdlet can be a great help.
Running ‘show-command’ followed by the cmdlet you wish to work with will give you a GUI based form, where you can specify exactly what you want to run. For example, running:
Show-Command New-Cluster
Presents this form:
Using this form, it’s straight forward to build the command that you need:
Once satisfied you can either run the resulting command directly, or you can copy the code to the clipboard. The code generated from the example above looks like this:
New-Cluster -Name Test-Cluster -Confirm -DrsAutomationLevel FullyAutomated -DrsEnabled -DrsMode FullyAutomated -HAAdmissionControlEnabled -HAEnabled -VMSwapfilePolicy WithVM
I think this is a great way for those new to PowerCLI to start using it for accomplishing tasks straightaway! Just bear in mind that you will need Powershell v3, as the show-command cmdlet wasn’t introduce until that version.