Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell batch pipe

The following line works fine in powershell 2.0.

servermanagercmd.exe -query | Select-String "Application Server" -Context 0,13

But when I incorporate it into my batch file it only attempts to run the first part and then returns an error when it gets to Select-String. Does anyone know how to make sure that it reads the whole line? I tried the ^ before my pipe, but it still won't recognize the full line.

like image 718
cmluciano Avatar asked Oct 28 '25 14:10

cmluciano


1 Answers

You're trying to use one of PowerShell's built-in commands from cmd.exe and that won't work. However you could execute PowerShell from a .bat file, passing in the command you want to execute:

powershell.exe -command "& { servermanagercmd.exe -query | Select-String 'Application Server' -Context 0,13 }"
like image 50
Keith Hill Avatar answered Oct 31 '25 05:10

Keith Hill