How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all?
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
.
The below cmdlet will return the PowerShell version.
$PSVersionTable.PSVersion.Major
Extending the answer with a select operator:
Get-Host | select {$_.Version}
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.
You can verify that Windows PowerShell version installed by completing the following check:
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/
I found the easiest way to check if installed was to:
cmd
, then OK)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.