Determine installed PowerShell version

前端 未结 19 2595
半阙折子戏
半阙折子戏 2020-11-22 09:40

How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all?

19条回答
  •  忘了有多久
    2020-11-22 10:06

    Since the most helpful answer didn't address the if exists portion, I thought I'd give one take on it via a quick-and-dirty solution. It relies on PowerShell being in the path environment variable which is likely what you want. (Hat tip to the top answer as I didn't know that.) Paste this into a text file and name it

    Test Powershell Version.cmd

    or similar.

    @echo off
    echo Checking powershell version...
    del "%temp%\PSVers.txt" 2>nul
    powershell -command "[string]$PSVersionTable.PSVersion.Major +'.'+ [string]$PSVersionTable.PSVersion.Minor | Out-File ([string](cat env:\temp) + '\PSVers.txt')" 2>nul
    if errorlevel 1 (
     echo Powershell is not installed. Please install it from download.Microsoft.com; thanks.
    ) else (
     echo You have installed Powershell version:
     type "%temp%\PSVers.txt"
     del "%temp%\PSVers.txt" 2>nul
    )
    timeout 15
    

提交回复
热议问题