cmluciano
cmluciano

Reputation: 557

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.

Upvotes: 4

Views: 4868

Answers (1)

Keith Hill
Keith Hill

Reputation: 201632

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 }"

Upvotes: 10

Related Questions