PowerTip: Capture the output of a Linux application in PowerShell


Summary: Use the built-in features of PowerShell to obtain data produced by a Linux application.

Hey, Scripting Guy! Question Can I run a Linux application like ls and capture its output in PowerShell?

Hey, Scripting Guy! Answer You certainly can!  It’s no different from when you normally grab output from any other command in Windows.   To grab the output of the ls command, for example, just assign it to a PowerShell object as you normally would.

$stuffonscreen=(ls)

The captured output will be all text, and you can run standard methods, Search-String and regular expressions against it.

The Doctor

Comments (0)

Skip to main content