craig craig - 1 month ago 13x
C# Question

ValidateSet() decoration doesn't generate tab completion

Shay Levy's comment in POWERSHELL SCRIPTING WITH [VALIDATESET] suggest that decorating a PowerShell parameter with

should result in tab completions:

One of the benfits of using ValidateSet (or Enum types) in PowerShell
3.0 is that you get tab expansion on the ValidateSet/Enum values.

I can't seem to get this to work in a PowerShell function or C# Cmdlet.


function Get-LogonToken {


[Parameter(Position = 0, Mandatory = $true)]
[string] $ServerName,

[Parameter(Position = 1, Mandatory = $true)]
[ValidateSet("secEnterprise", "secLDAP", "secWinAD")]
[string] $Authentication,

[Parameter(Position = 2, Mandatory = $true)]
[string] $Username,

[Parameter(Position = 3, Mandatory = $true)]
[SecureString] $Password


Write-Verbose "ServerName: $ServerName"
Write-Verbose "Authentication: $Authentication"
Write-Verbose "Username: $Username"
Write-Verbose "Password: $(ConvertFrom-SecureString $Password)"



[System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.Get, "LogonToken")]
public class GetLogonToken : System.Management.Automation.Cmdlet

[System.Management.Automation.Parameter(Position = 0, Mandatory = true)]
public string ServerName
get { return server; }
set { server = value; }
private string server;

[System.Management.Automation.Parameter(Position = 1, Mandatory = true)]
[ValidateSet("secEnterprise", "secLDAP", "secWinAD")]
public string Authentication
get { return authentication; }
set { authentication = value; }
private string authentication;

[System.Management.Automation.Parameter(Position = 2, Mandatory = true)]
public string Username
get { return username; }
set { username = value; }
private string username;

[System.Management.Automation.Parameter(Position = 3, Mandatory = true)]
public SecureString Password
get { return password; }
set { password = value; }
private SecureString password;




PS> get-logontoken -verbose

cmdlet Get-LogonToken at command pipeline position 1
Supply values for the following parameters:
ServerName: server
Authentication: sec<tab> (nothing generated)

What am I missing?


Thanks for posting as a separate question craig. Now I see what the problem is.

You can't tab complete when PowerShell prompts you for a missing Mandatory value (at run-time), only when you're first typing out the cmdlet:

Get-LogonToken -Authentication secTAB