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

Batch file run Powershell and hides the output

我有一个批处理文件来执行 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