Redirect standard input (read-host) to a Powershell script


Here’s a sample powershell script:

Here’s a sample ‘test.txt’ file:

And we want to pass piped input to it from powershell. Here’s some I have tried:

even just trying to echo input doesn’t work either:

Every example above that doesn’t produce an error always prompts the user instead of accepting the piped input.

Note: My powershell version table says 4.0.-1.-1


Edit/Result: To those looking for a solution, you cannot pipe input to a powershell script. You have to update your PS file. See the snippets below.


The issue is that your script \.test.ps1 is not expecting the value.

Try this:

Alternatively, you can use the magic variable $input without a param part (I don’t fully understand this so can’t really recommend it):


Redirect standard input (read-host) to a Powershell script by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply