批处理文件运行Powershell并隐藏输出

批处理文件运行Powershell并隐藏输出,powershell,batch-file,window,Powershell,Batch File,Window,我有一个批处理文件来执行PowerShell脚本: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -command .\MyPowerShell.ps1 echo message1 echo message2 批处理可以毫无问题地运行PowerShell,但CMD提示符会显示PowerShell脚本的输出。

我有一个批处理文件来执行PowerShell脚本:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -command .\MyPowerShell.ps1
echo message1
echo message2
批处理可以毫无问题地运行PowerShell,但CMD提示符会显示PowerShell脚本的输出。是否可以在CMD提示符中隐藏PowerShell脚本的输出?我仍然需要在CMD提示符中传递一些消息,因此终止CMD不是一个选项。任何帮助都将不胜感激

@echo off
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -command .\MyPowerShell.ps1
cls
echo message1
echo message2
pause

我使用命令cls清除批处理脚本以隐藏它

Powershell有它自己的重定向,但是如果您正在从
cmd
运行
Powershell
,并且根本不想看到输出,请将输出重定向到
nul

@echo off
"%windir%\System32\WindowsPowerShell\v1.0\powershell.exe"  -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -command .\MyPowerShell.ps1 >nul 2>&1
echo message1
echo message2

我不太明白你的问题。有几种方法可以抑制Powershell中的输出,如
Out Null
@Rno感谢您的回复,我最后尝试在命令中添加Out Null,但命令提示符立即关闭,PS脚本未执行。请修改ps1,使其不会产生任何错误output@SantiagoSquarzon你的建议很明智。我也要试试!输出仍然显示为0.5秒,并立即消失。这对我的项目有效。非常感谢你!