批处理文件运行PowerShell并隐藏输出的方法如下所示:
@echo off powershell.exe -noprofile -executionpolicy bypass -file "C:\path\to\your\script.ps1" >nul 2>&1
说明:
nul 表示将输出重定向到 nul 设备,即不会显示在屏幕上。
示例代码:
@echo off powershell.exe -noprofile -executionpolicy bypass -command "Write-Output 'This is a PowerShell script'"
运行结果:
没有输出。
请注意,如果要运行 PowerShell 脚本的命令比较复杂,建议将其保存为单独的 .ps1 文件,并使用上述示例中的 -file 参数来运行脚本。