31 July 2019

Even More Efficient PowerShelling with PowerCLI Argument Completers!

Updated vNugglets PowerShell Module! Ya-hoo -- tab-completion for several parameters' values and for many VMware PowerCLI cmdlets! We all are accustomed to being super fast on the command line by leveraging tab-completion of, well, most things: paths, cmdlet names, process names, service names, etc.. We also doit in things like editors that have IntelliSense. But, while we may also want to have that same experience with inventory objects in our virtual infrastructures, we do not yet have such capabilities.

So, we here at vN took the time to hammer out some goodness for enabling tab-completion of parameter values on VMware PowerCLI cmdlets -- now we can tab-complete values of actual inventory objects in a snap!

* Update 23 Aug 2019:
We added a Getting Started section in the Docs in the GitHub repo. See https://github.com/vNugglets/PowerShellArgumentCompleters/tree/master/docs for such information, to get going straight away!
* end of 23 Aug 2019 update
What:
  • This comes in the form of an argument completer add script, soon to be in PowerShellGallery, and with code already at https://github.com/vNugglets/PowerShellArgumentCompleters
  • Initially, for the VMware.PowerCLI module, this adds 301 tab-completion capabilities across 240+ cmdlets and a dozen different parameters
How:
  • You register the argument completers in a PowerShell session by first importing any/all VMware PS modules you'll be using, and then running the Register-VMwarePowerCLIArgumentCompleter script from said repo above (again, this will eventaully be available in the PowerShell gallery for easier consumption/updates)
Example:
  • The following would result in the user being able to tab through all of the completions for the given parameter after which they pressed the Tab key
    • Get-VM -Name matt<tab>
    • Get-VMHost myho<tab>
    • Get-Datastore -VM myvm0<tab>
    • Get-VDSwitch -VMHost <tab>
Further Reading:
  • For more detail/background as this pertains to the VMware.PowerCLI module, see the corresponding Support Natural PowerShell Interactive Behavior: tab completion idea at powercli.ideas.aha.io
  • To be clear (and to acknowledge others before): others have written about such things on small scale (adding tab-completion for the -Name parameter for something like Get-VM, for example), but this current goodness is an effort to add far more tab-completions to some of our favorite modules
  • and, for when you want to Get-ArgumentCompleter, Chris Dent made the excellent (and deep) Get-ArgumentCompleter.ps1 script with which we can see the registered argument completers in our PowerShell session. See his GitHub gist at https://gist.github.com/indented-automation/26c637fb530c4b168e62c72582534f5b
Time to get tabbin'!  And, for when you have stellar ideas for more completers, either let us know, or collaborate with us on GitHub -- we'll make great things together!

No comments:

Post a Comment