How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all?
This is the top search result for "Batch file get powershell version", so I'd like to provide a basic example of how to do conditional flow in a batch file depending on the powershell version
Generic example
powershell "exit $PSVersionTable.PSVersion.Major"
if %errorlevel% GEQ 5 (
echo Do some fancy stuff that only powershell v5 or higher supports
) else (
echo Functionality not support by current powershell version.
)
Real world example
powershell "exit $PSVersionTable.PSVersion.Major"
if %errorlevel% GEQ 5 (
rem Unzip archive automatically
powershell Expand-Archive Compressed.zip
) else (
rem Make the user unzip, because lazy
echo Please unzip Compressed.zip prior to continuing...
pause
)