Determine installed PowerShell version

前端 未结 19 2394
半阙折子戏
半阙折子戏 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:16

    I have made a small batch script that can determine PowerShell version:

    @echo off
    for /f "tokens=2 delims=:" %%a in ('powershell -Command Get-Host ^| findstr /c:Version') do (echo %%a)
    

    This simply extracts the version of PowerShell using Get-Host and searches the string Version

    When the line with the version is found, it uses the for command to extract the version. In this case we are saying that the delimiter is a colon and search next the first colon, resulting in my case 5.1.18362.752.

    0 讨论(0)
  • 2020-11-22 10:17

    The below cmdlet will return the PowerShell version.

    $PSVersionTable.PSVersion.Major
    
    0 讨论(0)
  • 2020-11-22 10:17

    Extending the answer with a select operator:

    Get-Host | select {$_.Version}
    
    0 讨论(0)
  • 2020-11-22 10:18

    You can directly check the version with one line only by invoking PowerShell externally, such as from Command Prompt

    powershell -Command "$PSVersionTable.PSVersion"
    

    According to @psaul you can actually have one command that is agnostic from where it came (CMD, PowerShell or Pwsh). Thank you for that.

    powershell -command "(Get-Variable PSVersionTable -ValueOnly).PSVersion"
    

    I've tested and it worked flawlessly on both CMD and PowerShell.

    0 讨论(0)
  • 2020-11-22 10:18

    You can verify that Windows PowerShell version installed by completing the following check:

    1. Click Start, click All Programs, click Accessories, click Windows PowerShell, and then click Windows PowerShell.
    2. In the Windows PowerShell console, type the following command at the command prompt and then press ENTER:

      Get-Host | Select-Object Version
      

    You will see output that looks like this:

    Version
    -------
    3.0
    

    http://www.myerrorsandmysolutions.com/how-to-verify-the-windows-powershell-version-installed/

    0 讨论(0)
  • 2020-11-22 10:19

    I found the easiest way to check if installed was to:

    • run a command prompt (Start, Run, cmd, then OK)
    • type powershell then hit return. You should then get the PowerShell PS prompt:

    C:\Users\MyUser>powershell
    
    Windows PowerShell
    Copyright (C) 2009 Microsoft Corporation. All rights reserved.
    
    PS C:\Users\MyUser>
    

    You can then check the version from the PowerShell prompt by typing $PSVersionTable.PSVersion:

    PS C:\Users\MyUser> $PSVersionTable.PSVersion
    
    Major  Minor  Build  Revision
    -----  -----  -----  --------
    2      0      -1     -1
    
    PS C:\Users\MyUser>
    

    Type exit if you want to go back to the command prompt (exit again if you want to also close the command prompt).

    To run scripts, see http://ss64.com/ps/syntax-run.html.

    0 讨论(0)
提交回复
热议问题