public void WriteError(ErrorRecord errorRecord) { var psobj = PSObject.AsPSObject(errorRecord); // if merged with stdout, we can later on check to which stream the object usually belongs psobj.WriteToErrorStream = true; ErrorStream.Write(psobj); ExecutionContext.AddToErrorVariable(errorRecord); if (MergeErrorToOutput) { OutputStream.Write(psobj); } }