Auto Complete User Input PowerShell 2.0

Question:

I have a large list of data (over 1000 different values) and I want the user to be able to select certain values from the list from a PowerShell console.

What is the easiest way from within the console to allow the user to quickly select values?

I would like to do something like tab completion or the ability to use the arrow keys to scroll through the values but I am not sure how to do either of these things.

Any advice would be greatly appreciated.

Answer:

PowerShell tab completion can be extended to custom parameters and parameter values (in v3). However, this is a property of advanced functions. You can use the ValidateSetAttribute to do that.

Check the Technet help topic on advanced functions: http://technet.microsoft.com/en-us/library/hh847806.aspx

You can replace the tabexpansion (v2) and tabexpansion2 (v3) function in PowerShell to auto complete parameter values outside of advanced functions. You can get a basic definition of this in PowerShell v3 by running

Here is an example of showing custom tab expansion function.

http://www.powershellmagazine.com/2012/11/29/using-custom-argument-completers-in-powershell-3-0/

But, if you want to the user to be able to auto complete values for a Read-Host kind of input, you need to write a proxy for Read-Host to achieve that.

You can, optionally, look at PowerTab module at http://powertab.codeplex.com/

Source:

Auto Complete User Input PowerShell 2.0 by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply