0
我通過DOS提示符運行Powershell命令,我想在開始運行我的命令之前檢查是否安裝了Powershell。如果沒有顯示下面的實際錯誤,powershell不存在,我希望腳本退出。這裏是我的腳本:DOS返回ErrorLevel沒有運行程序
@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.
實際上,上述powershell命令錯誤出來爲好。我不得不使用PowerShell「Write-Output」'n'「2> NUL –