I am facing some peculiar issue in PowerShell 2.0. I am not an expert in PS but occasionally write/edit few scripts to work with Nagios monitoring tool. Requesting help form PS experts. Your help will be appreciated.
The script ExServiceAlert10.ps1 is attached in this post. The script is working fine and shows no error, if I directly execute it in PowerShell command like below.
PS C:\Windows\system32> D:\ExServiceAlert10.ps1
But shows error when execute in Normal windows command prompt or from Nagios NSClient++ like below.
Normal command Prompt execution:
D:>echo .\ExServiceAlert10.ps1 ; exit $LastExitCode | powershell.exe -command -
From nagios NSclient++ execution via check_nrpe:
cmd /c echo scripts\ExServiceAlert10.ps1; exit $LastExitCode | powershell.exe -command â€“
The error I am getting by the above 2 ways is as follows.
Missing expression after unary opearator ‘-’.
At line:1 char:2
- CategoryInfo : ParseError: (-:String) , ParentContainsErrorRecordException
+FullyQualifiedErrorId : MissingExpressionAfterOperator
I am executing this script in PowerShell 2.0 and tried various debugging methods to solve this for past 1 week with no success.
Please let me know if any further information required here.
Thank you in advance.