Powershell批管 [英] powershell batch pipe

查看:59
本文介绍了Powershell批管的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下行在Powershell 2.0中可以正常工作.

The following line works fine in powershell 2.0.

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

但是,当我将其合并到批处理文件中时,它仅尝试运行第一部分,然后在到达Select-String时返回错误.有谁知道如何确保它能读取整行?我在管道前尝试了^,但仍然无法识别整行.

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.

推荐答案

您正尝试使用cmd.exe中PowerShell的内置命令之一,但该命令无法正常工作.但是,您可以从.bat文件执行PowerShell,并传入要执行的命令:

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

这篇关于Powershell批管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆