I get an error when running a script via the cli, but not Powershell ISE! I do not understand why.
ERROR: [06/09/2016 07:57:26] System.Management.Automation.RuntimeException: Method invocation failed because [System.Object] does not contain a method named 'op_Addition'. at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
The code snippet:
$logMessages = @() ... Function Timestamp-Message([string] $message){ $msg = New-Object System.Object $msg | Add-Member -type NoteProperty -name TimeStamp -value $(Get-Date) $msg | Add-Member -type NoteProperty -name Message -value $message return $msg } ... Process { Try { ... $logMessages += Timestamp-Message($message)The error occurs on this last statement. And this exact statement is executed a few lines before with no exception, storing the object as the first member of the array.