I am trying to write a simple text manipulation filter in powershell (5.1 on W10-64 bits). My goal is to use it as part of a pipeline in a batch (.bat), e.g.:
command1.exe | powershell "...my filter..." | command2.exe
I am facing a weird problem: "Read-Host" cmdlet always echoes its input. Example:
echo 1234 | powershell "$a=Read-Host"
produces
1234
(NOTE: see PowerShell: Disable echo in Read-Host).
How can I avoid this unexpected echo? Is there any alternate way to read STDIN in powershell?
NOTE2: I know I could do all the pipeline work inside powershell, but for many reason this doesn't fit my case. What I want is a "generic filter" suitable to be part of a pipeline in a ".bat". And, no, a temporary file to store intermediate data is not an option.
EDIT: as noted by "Compo", MS documentation says this about Read_Host:
You cannot pipe input to this cmdlet
So there is no point in trying to make it work.
EDIT2: As explainded by "mklement0", "[Read_Host] does accept pipeline, i.e. stdin input from the outside, such as when provided to PowerShell's CLI". The real problem is that it is intended to simplify user input, not to give generic access to stdin.
The actual question is: Is there any alternate way to read STDIN in powershell?