Page 1 of 1

How to check if powershell is installed?

Posted: 26 Sep 2013 14:17
by Adrianvdh
Hello everyone... :)

I am asking a rather simple question but I can't get my code to work with it.
How do I check if powershell is installed?

I have tried...

Code: Select all

if exist "powershell.exe" (echo Exist ) else (echo Sorry mate )
pause


But I could probably get that to work using the correct directories.

But I don't want to have messy code with the following directories saying v1.0, v2.0 etc and x86, x64 version directories.

How can I solve this with a few lines of code?

BTW I need this, because if powershell is not installed my script would shout out an error and rather run on wget to the my job..

Thanks. Hope you can help :)

Re: How to check if powershell is installed?

Posted: 26 Sep 2013 17:15
by aGerman
Powershell should always be placed in the PATH environment. For that reason the ~$path modifier of FOR variables should be suitable.

Code: Select all

for %%i in (powershell.exe) do if "%%~$path:i"=="" (echo Sorry mate) else echo Exists

Regards
aGerman

Re: How to check if powershell is installed?

Posted: 27 Sep 2013 04:49
by Adrianvdh
Thanks