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)?
How to find out the highest, installed Powershell version FROM CommandPrompt?
Moderator: DosItHelp
Re: How to find out the highest, installed Powershell version FROM CommandPrompt?
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.
Errors are redirected. So, this should still work if none of the newer versions are installed.
Steffen
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
Steffen