How to use cmd type pipe (/piping) in PowerShell?


In cmd (and bash), pipe “|” pushes output to another command in the original format of the first command’s output (as string).

In PowerShell, everything that comes out the pipe is an object (even a string is a string object).

Because of that, some commands fail when run in a PowerShell command window as opposed to a Windows command window.


When this command is run in the Windows command prompt window it works properly – directory listing of C:\windows gets compressed into test.gz file.

The same command in PowerShell fails, because PowerShell does not use cmd-style pipe and replaces it with PowerShell pipe (working with array of file system items).

Q. How do you disable the default piping behavior in PowerShell to make traditional Windows commands work identically in PowerShell?

I tried using the escape character “" before the pipe "|“, but it didn’t work. I also tried invoke-expression -command "command with | here", but it also failed.


if you want to send strings down the pipeline you can use the cmdlet “out-string”

For Example:

If you are specifically looking for a PowerShell way to zip up files, check out the PowerShell Community Extensions. there are a bunch of cmdlets to zip and unzip all kinds of files.


How to use cmd type pipe (/piping) in PowerShell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply