我正在通过 CMD 提示符运行 Powershell 命令,我想在开始运行命令之前检查是否先安装了 Powershell。如果 powershell 不存在而不显示下面的实际错误,我希望脚本退出。这是我的脚本:
@echo off
setlocal enabledelayedexpansion
:: Check to see if Powershell is installed
powershell.exe -command {"test"} > NUL
if errorlevel 1 (
echo/Powershell is NOT Installed
EXIT
) else (
goto PSI
)
:PSI
powershell Set-ExecutionPolicy RemoteSigned
我遇到的问题是我将其作为输出:
Powershell is NOT Installed
'powershell.exe' is not recognized as an internal or external command,
operable program or batch file.