2012-06-15 4 views
0

Je lance des commandes Powershell via une invite DOS et je voudrais vérifier si Powershell est installé avant de commencer à exécuter mes commandes. Je voudrais que le script se termine si powershell n'existe pas sans montrer l'erreur réelle ci-dessous. Voici mon script:DOS Retourne ErrorLevel sans exécuter le programme

@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 

Le problème que je vais avoir est que je reçois cela comme sortie:

Powershell is NOT Installed 

'powershell.exe' is not recognized as an internal or external command, 
operable program or batch file. 

Répondre

1

figured it out! J'ai dû utiliser 2> NUL à la place de NUL pour rediriger la sortie:

:: Check to See if Powershell is Installed 
powershell.exe test 2>NUL 
    if errorlevel 1 (
     echo/Powershell is NOT Installed 
    EXIT 
    ) else (
    goto PSI 
    ) 
+0

En fait, la commande powershell ci-dessus est également erronée. Je devais utiliser powershell "Write-Output '' n '" 2> NUL –

Questions connexes