Page 1 of 1

How to find out the highest, installed Powershell version FROM CommandPrompt?

Posted: 12 Apr 2022 23:14
by tobwz
As you know there is a system break in installation release procedure between PowerShell v5.1 and later Powershell versions (e.g. current v7.2.2).

Until v5.1 users could find out on CommandPrompt the maximum locally installed Powershell version by entering:

PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "&{Get-Host | Select-Object Version}"

or

PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "$psversiontable"

This does not work for newer Powershell versions any more.

If newer Powershell versions are installed: How can I find out their version label from Command Prompt (and DOS batch script) (without fiddling around in Registry and/or installation directory)?

Re: How to find out the highest, installed Powershell version FROM CommandPrompt?

Posted: 16 Apr 2022 13:56
by aGerman
I guess this does still work (at least it works for me). The only difference is that you have to run "pwsh.exe" for the new versions.

Code: Select all

@echo off &setlocal
for /f "delims=" %%i in ('2^>nul powershell.exe -nop -ep Bypass -c "$PSVersionTable.PSVersion|foreach{''+$_.major+'.'+$_.minor}"') do set "psver=%%i"
for /f "delims=" %%i in ('2^>nul pwsh.exe -nop -ep Bypass -c "$PSVersionTable.PSVersion|foreach{''+$_.major+'.'+$_.minor}"') do set "psver=%%i"
echo %psver%
pause
Errors are redirected. So, this should still work if none of the newer versions are installed.

Steffen

Re: How to find out the highest, installed Powershell version FROM CommandPrompt?

Posted: 27 Apr 2022 07:18
by tobwz
It works.
Thank you