On Jan 18, 8:55*am, Shay Levi <n...@xxxxxx> wrote:
> Works fine for me :
>
> PS > $script3 = [scriptBlock] { param($x,$y); Write-Host "v3 X: $x Y:$y";
> $x+$y}
> PS > $script3.InvokeReturnAsIs(15,16)
> v3 X: 15 Y:16
> 31
>
> PS > $script3.Invoke(15,16)
> v3 X: 15 Y:16
> 31
>
> -----
> Shay Levi
> $cript Fanatichttp://scriptolog.blogspot.com
> This is a little disturbing. What OS are you running on? I'm on
Windows 2003 Server.
As to why I'm needing to invoke a script, it's not worth digging into
the problem set. But as I said I get the same problem with
PSScriptMethod
How does this work for you?
$object = new-object Management.Automation.PSObject
$script1 = [scriptBlock] { param($x,$y); Write-Host "Method1 X: $x Y:
$y"; $x+$y}
$script2 = [scriptBlock] { $x = $Args[0]; $y = $Args[1]; Write-Host
"Method2 X: $x Y:$y"; $x+$y}
$member1 = new-object management.automation.PSScriptMethod "Method1",
$script1
$object.psobject.members.Add($member1)
$member2 = new-object management.automation.PSScriptMethod "Method2",
$script2
$object.psobject.members.Add($member2)
$object.Method1(5,6)
Method1 X: Y:
$object.Method2(7,8)
Method2 X: 7 Y:8
15