powershell errors
wagosia opened this issue · comments
How to catch errors,warnings, confirmation messages from powershell commands ?
Thanks for the issue. Please post a small snippet of what you're trying to do. I suspect errors and warnings will be easier than confirmation messages.
Thanks
Doug
When executing a Powershell command it can provide standard output, error or warning. When using edge-ps, we have "result" as standard output however I don't know how to find out if the command did run properly when there is no output from Powershell command or error / warning was present.
I know that we can use errorvariable or warningwariable in order to catch them in Powershell, however how to pass them back to nodejs ?
Only way I can think of is catching -ev -we -ov into separate variables then creating a powershell object which would have result, error, warning, then convert this object into json string and pass it as "result". However this is such a long way to do it I hope that there is a better one.
My example:
var test = edge.func('ps', function() {/*
$PARAM = "$inputFromJS" | ConvertFrom-Json;
Get-EventLog -logname $PARAM.logname -ev ownE -wv ownW -ov ownO > $null
$OWN = @{}
$OWN.error = $ownE
$OWN.warning = $ownW
$OWN.result = $ownO
$OWN | ConvertTo-JSON
*/});
It's still not catching all errors :-( for example following error is not going to be "saved" into errorvariable
PS C:\Users\wagosia\Desktop> get-eventlog -logname Application -newest 5a -ev test
Get-EventLog : Cannot bind parameter 'Newest'. Cannot convert value "5a" to type "System.Int32". Error: "Input string
was not in a correct format."
At line:1 char:43
+ get-eventlog -logname Application -newest 5a -ev test
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Get-EventLog], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetEventLogCommand
PS C:\Users\wagosia\Desktop> $test
PS C:\Users\wagosia\Desktop>
Thanks for the issue. I haven't layered in pushing errors back to node. Let me know if you'd want to take a crack at that.
I have a similar problem: if i write some syntax error on the powershell text, i have no indication of the error when back on Node. Any advance on this ?
The C# that handles the PowerShell engine and runspace does not handle returning errors from the pipeline etc. That needs to be extended.