Suppose I write a simple script that takes $name as a cli parameter and print it. I know that when I invoke the script it can autocomplete -name, but is it possible to give PowerShell a list of values from which to autocomplete the value assigned to $name?
1 Answer
You want the [ValidateSet()] feature for your parameter. It is used as such:
Function Test-Me{
Param(
[ValidateSet("Matt","John","Andrew")][String]$Name
)
"You designated $Name"
}
Then when you access the function and go to fill in the -Name argument it will pop out a list of applicable names from the list provided.

2 Comments
Yotam
That's great, thanks! Little problem: only works on 8.1, not on server 2012 R2. Any idea why? thanks anyway
TheMadTechnician
Sorry, I missed your comment until just now. I'm afraid that I do not know why it doesn't work on Server 2012 R2, I do not have a server available to me. Are you using the ISE in both cases? I think tab-completion should still work either way. Sorry, I can't really test on server.