Batch file ErrorAction SilentlyContinue一元运算符后缺少表达式

Batch file ErrorAction SilentlyContinue一元运算符后缺少表达式,batch-file,powershell,Batch File,Powershell,我要做的是抑制错误/警告消息并继续执行批处理脚本。所以我现在做的是这样的: SET psh_path="%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" %psh_path% -ExecutionPolicy ByPass -ErrorAction "SilentlyContinue" -Command "Test_invalid_command;" %psh_path% -ExecutionPolicy ByPass

我要做的是抑制错误/警告消息并继续执行批处理脚本。所以我现在做的是这样的:

SET psh_path="%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe"

%psh_path% -ExecutionPolicy ByPass -ErrorAction "SilentlyContinue" -Command "Test_invalid_command;"
%psh_path% -ExecutionPolicy ByPass -Command ". '.\silentlyContinue.ps1'; Test_invalid_command;"
但这给了我错误:

Missing expression after unary operator '-'.
At line:1 char:2
我发现解决这个问题的一种方法是使用命令创建
silentlyContinue.ps1
文件

$ErrorActionPreference = "SilentlyContinue"
然后像这样使用点源:

SET psh_path="%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe"

%psh_path% -ExecutionPolicy ByPass -ErrorAction "SilentlyContinue" -Command "Test_invalid_command;"
%psh_path% -ExecutionPolicy ByPass -Command ". '.\silentlyContinue.ps1'; Test_invalid_command;"
我关心的是如何在第一种情况下实现这一点,我的意思是将选项传递给-ErrorAction检查:

SET psh_path="%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe"

%psh_path% -ExecutionPolicy ByPass -Command "Test_invalid_command" -ErrorAction SilentlyContinue

-ErrorAction不是Powershell.exe的参数

运行powershell.exe/?查看它的参数列表

-ErrorAction设置需要包含在您的命令脚本中,可以是显式的,也可以是源于您正在执行的另一个脚本