I will let the Dev guys give you a detailed answer, but the short answer is
that you dont have to have '-'. Most if not all cmdlets will gladly process
parameters without the - although without the '-' it has to be placement
sensative. I know this is not a cmdlet, but the same applies
function foo {
param($say,$hello)
$say
$hello
}
Now... I can call that a couple of ways
foo Hi there
or
foo -say Hi -hello There
From my understanding when you pass a parameter using {} it is seen as an
array.
So when you do:
invoke-expression {gps}
you are passing an array to invoke-expression... which it apparently doesn't
take kindly to.
Again.... just my take on it.
--
Brandon Shell
---------------
Stop by my blog some time
http://www.bsonposh.com/
Try the "Search of Powershell Blogs"
--------------------------------------
"Andrew Savinykh" <andrewsav@gmail.com> wrote in message
news:OqwKUzbRHHA.4632@TK2MSFTNGP04.phx.gbl...
>I understand that this command is wrong and I understand how to make it
>right. What i don't understand is the error message. What's going on under
>the hood producing this error message:
> PS F:\> invoke-expression { gps }
> Invoke-Expression : A parameter cannot be found that matches parameter
> name 'gps '.
> At line:1 char:18
> + invoke-expression <<<< { gps }
>
> Any ideas?
>
> Why on earth gps is considered to be a paramter name in the message it's
> not prefixed by '-' sign or something.
> From help:
> To provide a script block as the value of the Command parameter, you must
> include it within quotation marks. Otherwise, the shell will recognize the
> script block and evaluate it rather than pass it in a literal form as the
> value of the Command parameter.
>
> So I would imagine that the parser would recognize { gps } as a
> scriptblock and process it. Of course the scriptblock parameter would make
> no sense for invoke-expression at which stage it will happily bug out, but
> what happens in reality is something different and I would like to know
> what.
>
> One guess would be that 'gps ', that is displayed is exactly {
> gps }.tostring(), so the parser tries to cast the parameter to a string,
> which is only natural. But why it is refering to it as to parameter
> *name*, where it's obvious that in fact's it's *value*.
>
> Just to re-iterate, I don't really need to hear how to write this
> statement so it works, I know this. The question is, why this statement
> gives this particular error message and how exactly command line parsing
> is processed. Also I'd like to mention that I've thoroughly read
> about_parsing. There is a vague paragraph there saying:
>
> Get-Command "-type" cmdlet
>
> PowerShell will attempt to use the "-type" value as an argument to the
> first positional parameter, while the "cmdlet" argument will be treated as
> a parameter name, causing the command to fail.
>
> Why cmdlet will be treated as a parameter name is beyond me. it doesn't
> have hyphen.