Bat echo输出代码PowerShell

时间:2017-12-23 21:48:32

标签: windows powershell batch-file cmd

我有一行蝙蝠脚本:

echo ($a = (quser) -replace "\s{2,}" , ";" | Select-String -pattern console -notmatch | Select-string -pattern ID -notmatch)>>ScriptV3.ps1 

但是当我启动这一行时,我的bat搜索识别管道|,但是在这里,管道是我的PowerShell脚本。

如何为我的批处理脚本隐藏此管道,但我在PowerShell脚本中找到了此管道。

谢谢!

PS:如果我写:

echo "$a = (quser) -replace "\s{2,}" , ";" | Select-String -pattern console -notmatch | Select-string -pattern ID -notmatch">>ScriptV3.ps1 
带引号的

,批量工作但在PowerShell中不起作用:(

1 个答案:

答案 0 :(得分:1)

尝试

echo ($a = (quser) -replace "\s{2,}" , ";" ^| Select-String -pattern console -notmatch ^| Select-string -pattern ID -notmatch)>>ScriptV3.ps1 

管道重定向的优先级高于echo,需要进行转义。

相关问题