Monday, October 29, 2012

Powershell ScriptMethod weirdness!


PS C:\> $fooBlock = {param ([parameter(mandatory=$true)]$bar)"bar $bar"}
PS C:\> &$fooBlock <-- ask="ask" bar="bar" for="for" p="p" parameter="parameter" the="the" will="will">...
PS C:\> new-item -Path function:\ -name foo -Value $fooblock
PS C:\> foo <-- ask="ask" bar="bar" for="for" p="p" parameter="parameter" the="the" will="will">...
PS C:\> $fooScriptMethod = ""| Add-Member -MemberType scriptmethod -Name Foo -Value $fooblock -pass
PS C:\> $fooScriptMethod.foo() <-- _not_="_not_" ask="ask" bar="bar" for="for" p="p" parameter="parameter" the="the" will="will">
Also OverloadDefinitions shows up empty.

PS C:\> $fooScriptMethod.foo.OverloadDefinitions
System.Object Foo();

Is it just me or is this weird behavior?