How to check if powershell is installed?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

How to check if powershell is installed?

#1 Post by Adrianvdh » 26 Sep 2013 14:17

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 :)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to check if powershell is installed?

#2 Post by aGerman » 26 Sep 2013 17:15

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

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: How to check if powershell is installed?

#3 Post by Adrianvdh » 27 Sep 2013 04:49

Thanks

Post Reply