{"id":80895,"date":"2016-11-25T11:59:46","date_gmt":"2016-11-25T19:59:46","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=80895"},"modified":"2019-02-18T09:10:19","modified_gmt":"2019-02-18T16:10:19","slug":"powertip-capture-the-output-of-a-linux-application-in-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-capture-the-output-of-a-linux-application-in-powershell\/","title":{"rendered":"PowerTip: Capture the output of a Linux application in PowerShell"},"content":{"rendered":"<p><strong>Summary<\/strong>: Use the built-in features of PowerShell to obtain data produced by a Linux application.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/> Can I run a Linux application like <strong>ls<\/strong> and capture its output in PowerShell?<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/> You certainly can!\u00a0 It\u2019s no different from when you normally grab output from any other command in Windows. \u00a0\u00a0To grab the output of the <strong>ls<\/strong> command, for example, just assign it to a PowerShell object as you normally would.<\/p>\n<p style=\"padding-left: 90px\"><code>$stuffonscreen=(ls)<\/code><\/p>\n<p style=\"padding-left: 30px\">The captured output will be all text, and you can run standard methods, <strong>Search-String<\/strong> and regular expressions against it.<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\" alt=\"The Doctor\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Use the built-in features of PowerShell to obtain data produced by a Linux application. Can I run a Linux application like ls and capture its output in PowerShell? You certainly can!\u00a0 It\u2019s no different from when you normally grab output from any other command in Windows. \u00a0\u00a0To grab the output of the ls command, [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568,639,641],"tags":[56,356,154,45],"class_list":["post-80895","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-powertip","category-windows-powershell","tag-guest-blogger","tag-powertip","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Use the built-in features of PowerShell to obtain data produced by a Linux application. Can I run a Linux application like ls and capture its output in PowerShell? You certainly can!\u00a0 It\u2019s no different from when you normally grab output from any other command in Windows. \u00a0\u00a0To grab the output of the ls command, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=80895"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80895\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=80895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=80895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=80895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}