Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture output of a batch file in powershell script

I need to capture the output created by a .bat file that is run from within a .ps1 file.

I'm new to powershell scripting but I know this isn't correct syntax. This best illustrates what I need to have happen.

I need to execute the facter.bat script then store its output in $Body so I can use that text later.

 "C:\Program Files (x86)\Puppet Labs\Puppet\bin\facter.bat" > $Body
like image 426
goto_10 Avatar asked Feb 19 '23 17:02

goto_10


1 Answers

This should do it:

$Body = & "C:\Program Files (x86)\Puppet Labs\Puppet\bin\facter.bat"

like image 69
EBGreen Avatar answered Feb 27 '23 18:02

EBGreen