active directory - PowerShell Param ValidateSet values with Spaces and Tab completion -
first, apologize posting question concerning powershell , tab completion. stackoverflow system identified several excellent questions answers concerning topic, seemed cumbersome implement simple new-adcomputer script.
the params going splat keep script readable. following code correctly tab completes in ise, must wrapped in double quotes.
is there native method in powershell allow tab completion of parameter sets include spaces?
param( [parameter(mandatory=$true)] [string]$server, [parameter(mandatory=$true)] [validateset('env1','env 2','env 3')] [string]$environment, [parameter(mandatory=$true)] [validateset('application','database','file , print','web server')] [string]$type ) $newaditems = @{ name = $server path = "ou=$type,ou=$environment,ou=smaller dn string" location ='mysite' description = "test description" managedby = "huge distingushed name string" whatif = $true } write-host @newaditems command used , error received:
ps c:\scripts> .\adcomputer-paramtest.ps1 -server thistest -environment env 3 -type file , print c:\scripts\adcomputer-paramtest.ps1 : cannot validate argument on parameter 'environment'. argument "env" not belong set "env1,env 2,env3" specified validateset attribute. supply argument in set , try command again.at line:1 char:58 + .\adcomputer-paramtest.ps1 -server thistest -environment env 3 -type file , pr ... + ~~~ edit: more information. if leave off single/double quotes in example script parameter environment, tab completion not work final parameter type. enclosing 2nd set in quotes correct it's way keep watch behavior.
no, @ least powershell 5.0 april 2015 preview. tab completion works describe. still need quotes around set work without throwing error. it's worth, add closing quote of matching type when start tab completion quote. example, pressing "f tab complete "file , print"(not sure when added feature).
i tried finding ways auto-include quotes part of validateset including additional double quotes around parameter sets , other attempts @ escaping quotes. attempts resulted in tab completion not working in various ways.
some of attempts, in case might try avenue:
[validateset('env1','"env 2"','"env 3"')] [validateset('env1',"'env 2'","'env 3'")] [validateset('env1','`"env 2`"',"`'env 3`'")] [validateset('env1','\"env 2\"',"\'env 3\'")]
Comments
Post a Comment