November 25th, 2016

PowerTip: Capture the output of a Linux application in PowerShell

Doctor Scripto
Scripter

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

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.