I'm experimenting with some job scheduling tool and trying to imitate warning state using specific exit code. In bash I can do something like echo 'warning message' >&2; exit $MyWarningCode In powershell it's a bit less intuitive:
1) Write-Warning writes to stdout, not stderror. So to imitate warning message I need to use Write-Error.
2) Write-Error - the output message includes "Write-Error". Its kind of weird. Shouldn't this be just "ERROR:", similar to what Write-Warning do?

Error records in PowerShell typically list the cmdlet name that generated the error record, to make debugging easier later on. PowerShell's stream concepts don't map _super_ well externally where you only really have stdout and stderr to work with, though; there's only so many ways you can condense 6 streams down to 2, and you'll always be losing out somewhere, so oftentimes it's mainly a matter of making the best of it.
make sense. Is there any plan to implement 1>&2 , it's currently throwing "operator is reserved for future use". This actually can be achieved with $Host.UI.WriteErrorLine , but it just looks more like a hack
There's generally not a need to do that, because there are Write-* cmdlets for each stream, so you can just use typical pipelines to send data to each stream, e.g., "this is an error" | Write-Error
That doesn't mean those operators are impossible to implement, but it isn't a simple problem; each stream in PowerShell is strongly typed (the output stream is the only exception), so it's likely at best you'll get any complex objects converted to string data when they're sent to a different stream, which may not always be desirable.
Not sure if there are plans for that, but I've not heard anything about that being planned... I think we may have existing issues for that, I'm not sure.
All about PowerShell streams https://devblogs.microsoft.com/scripting/understanding-streams-redirection-and-write-host-in-powershell/
Scripting Blog
Summary: June Blender explains how to understand and use streams in Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, is here. Today guest blogger, June Blender, explains how to understand and use streams in Windows PowerShell. To read more from June, see these Hey,
There really does need to be a way to send data to stderr without triggering ErrorAction. stderr is often used as a diagnostic data channel on POSIX-like systems, kept separate from stdout which is often used for streaming data being processed. In Powershell today, there's no way to emit debugging output while simultaneously pipelining pwsh with POSIX-native tooling. That leads to very awkward shims, and a general loss of debugging data streams.
Ideally, an invocation of pwsh would at minimum permit specifying file descriptors to map the event streams to, to let the plumbing get wired in to user expectations.
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.
Most helpful comment
There's generally not a need to do that, because there are
Write-*cmdlets for each stream, so you can just use typical pipelines to send data to each stream, e.g.,"this is an error" | Write-ErrorThat doesn't mean those operators are impossible to implement, but it isn't a simple problem; each stream in PowerShell is strongly typed (the output stream is the only exception), so it's likely at best you'll get any complex objects converted to string data when they're sent to a different stream, which may not always be desirable.
Not sure if there are plans for that, but I've not heard anything about that being planned... I think we may have existing issues for that, I'm not sure.