Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting an error when trying to run some examples #7

Open
stefanstranger opened this issue Mar 20, 2013 · 7 comments
Open

Getting an error when trying to run some examples #7

stefanstranger opened this issue Mar 20, 2013 · 7 comments

Comments

@stefanstranger
Copy link

When I run the following from the samples folder I get the following error:

D:\Install\Node\edge-powershell-master\samples\tryPowerShell> node .\test.js

D:\Install\Node\edge-powershell-master\samples\tryPowerShell\test.js:16
if (error) throw error;
^
System.AggregateException: One or more errors occurred. ---> System.InvalidCastException: Unable to cast object of type
'System.String' to type 'System.Collections.Generic.IDictionary2[System.String,System.Object]'. at Edge.PS.EdgePowerShell.<InvokeScript>d__2.MoveNext() in d:\Install\Node\edge-powershell-master\src\Edge.PowerShell \Edge.PowerShell\EdgePowerShell.cs:line 36 --- End of inner exception stack trace --- ---> (Inner Exception #0) System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Col lections.Generic.IDictionary2[System.String,System.Object]'.
at Edge.PS.EdgePowerShell.d__2.MoveNext() in d:\Install\Node\edge-powershell-master\src\Edge.PowerShell
\Edge.PowerShell\EdgePowerShell.cs:line 36<---

What am I doing wrong?

I've installed Node.js 0.8.19 and Edge.

/Stefan

@dfinke
Copy link
Owner

dfinke commented Mar 20, 2013

Thanks for trying Stefan. I'll get back to you shortly after I investigate.

@stefanstranger
Copy link
Author

Thnx

-----Original Message-----
From: "Doug Finke" [email protected]
Sent: ‎20-‎3-‎2013 20:53
To: "dfinke/edge-powershell" [email protected]
Cc: "stefanstranger" [email protected]
Subject: Re: [edge-powershell] Getting an error when trying to run some examples (#7)

Thanks for trying Stefan. I'll get back to you shortly after I investigate.


Reply to this email directly or view it on GitHub:
#7 (comment)

@dfinke
Copy link
Owner

dfinke commented Mar 20, 2013

Ok, sorry about that. I was in the middle of spiking out some ideas and checked them in. This version spins up a web server and serves up PowerShell files. So... Try this

node .\server.js

Then launch a browser and use this url

http://localhost:8080/powershell/test

You should get this

[
  4,
  16,
  36,
  64,
  100,
  144,
  196,
  256,
  324,
  400
]

You can see that it is executing test.ps1. It can also take two parameters like this.

http://localhost:8080/powershell/test?max=100&min=90
[
  8100,
  8464,
  8836,
  9216,
  9604,
  10000
]

You can create your own PowerShell files. Save them in the edge-powershell\samples\tryPowerShell directory. You execute it with the base url

http://localhost:8080/powershell

Then the base name of the file without the ps1 extension.

http://localhost:8080/powershell/myscript

Passing parameters follow the query string convention

http://localhost:8080/powershell/myscript?firstname=john&lastname=doe

I'm working towards merging the solution where you can run this as standalone or through a web server.

@cdhunt
Copy link

cdhunt commented Mar 21, 2013

Installed Express and set $env:PORT to an available port and it worked as expected.

So, I created this script.

param($script = 'Get-Process')

Invoke-Expression $script

It throws an error

                res.json(results.Result);
                                ^
TypeError: Cannot read property 'Result' of undefined

Simple scripts like "1..3" work. Maybe this has something to do with #6.

If I pipe to Select-Object -Property * it doesn't crash but returns an array of empty json objects.

[
  {},
  {},
  {},
  {},
  {}
]

@dfinke
Copy link
Owner

dfinke commented Mar 21, 2013

I believe it may work if you pipe it to Out-String

@cdhunt
Copy link

cdhunt commented Mar 21, 2013

Yes, that works as well as ConvertTo-JSON, but like you said, that's just a big string, not an object.

@dfinke
Copy link
Owner

dfinke commented Mar 21, 2013

Yep, so getting an "object" back is the challenge. I'm not sure how, I have some guesses. I'm wondering if/how PowerShell Web Access does it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants