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

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


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

For Example:

get-process | out-string

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.

http://pscx.codeplex.com


If you can pipe the output of (CMD) dir into gzip, then gzip apparently knows how to parse dir output. The (string) output from the PowerShell dir command (aka Get-ChildItem) doesn't look the same, so gzip likely would not be able to parse it. But, I'd also guess that gzip would be happy to take a list of paths, so this would probably work:

dir c:\windows | select -ExpandProperty FullName | gzip > test.gz

No warrantees express or implied.


If you really need to use the old school DOS pipe system in PowerShell, it can be done by running a command in a separate, temporary DOS session:

& cmd /c "dir c:\windows | gzip > test.gz"

The /c switch tells cmd to run the command then exit. Of course, this only works if all the commands are old school DOS - you can't mix-n-match them with PowerShell commands.

While there are PowerShell alternatives to the example given in the question, there are lots of DOS programs that use the old pipe system and will not work in PowerShell. svnadmin load is one that I've the pleasure of having to deal with.