Recently when at the Western Pennsylvania VMUG I was asked by Rob Velarde if I had tried Show-Command with PowerCLI, I know that PowerCLI5.1 R2 now supports PowerShell V3 where the Show-Command cmdlet was introduced so thought I would take a look.

Looking at a cmdlets syntax can be complicated for people who are new to PowerShell and PowerCLI, the below is an example of the New-VM cmdlet…

So what does all this mean?

The mixture of square brackets, angle brackets tell us what is required by a cmdlet and which items are positional, each line shows a separate parameter set (4 in this example), and that’s just the basics!

This can be confusing for people who are learning PowerCLI and just need to get the job done, what do they need to fill out, what are some of the options?

Show-Command

Show-Command is a great way to help people learn PowerCLI and the parameters they need to use for a given cmdlet. If I use Show-Command with New-VM we are presented with a graphical representation of the input for the New-VM Cmdlet:

Each parameter set is now represented by a new tab in the GUI:

We can easily see the required entries as they are marked with a * and fill out each part of the form to create a new virtual machine. Another cool feature of Show-Command is that if there are defined values for a parameter these will be listed in a selection box:

And the last cool feature which takes us back to helping the new people learn more is that once you have filled out the GUI you have a couple of options to show what the cmdlet would look like if you ran it at the console.

1. Hit the Copy button and paste it into a script editor or the PowerCLI console to see the fully completed cmdlet with parameters for what you just filled out.

2. Hit the Run button to submit the command and create the VM, next you can push the up arrow in the PowerCLI console to see the history and what the cmdlet would have looked like if you had not used the GUI, this is a great way of learning!

For example, the following GUI entries

After hitting Run and using the up arrow in the same console (or hitting copy) you would get the following PowerCLI code:

New-VM -Name MyVM1 -Template MyTemplate1 -Datastore MyDatastore1 -DiskStorageFormat Thin -VMHost MyVMHost1

Conclusion

You can see how using Show-Command can help simplify learning the inputs for a cmdlet, this is useful when getting started with PowerCLI (Or PowerShell for that matter) and also helps us understand more about parameter sets and required parameters.

Do you have any other easy ways to help new people learn PowerCLI or PowerShell? Make sure you comment below!

-Alan

Share this: Email

Print

Twitter

Facebook

Reddit

