This short article will should you a number of ways in which you can list the version of PowerShell installed on your loca system and on remote hosts.
How to List the PowerShell Version Installed on Local Computer
If you need to list the PowerShell version installed on your local system you can do so using the get-host
powershell command. For example:
> (get-host).version
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 1023
Now, another way you can do this is to use the $psversiontable
variable. This variable contains a bunch of information, including the Powershell version:
> $psversiontable
Name Value
---- -----
PSVersion 5.1.19041.1023
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1023
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Notice, unlike with the get-host
cmdlet, the way the version is displayed is as a single value here, rather than a table. Though if we look into psversion then we get the same output as with get-host
:
> ($psversiontable).psversion
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 1023
If you want to display the version in your own format you can do so by taking the bits you need, from the output of the get-host
cmdlet. For example, if you only need to return the major and minor build versions then you could use:
> write-host (get-host).version.major (get-host).version.minor -Separator .
5.1
How to List the PowerShell Version Installed on a Remote Host
If you have done the pre-requisite work to allow running PowerShell against remote hosts, you will be able to use the invoke-command cmdlet to query the PowerShell version of a remote host. To use Windows PowerShell remoting, the remote computer must be configured for remote management, which you can find out more about here.
With that in place, the following can be used to query the PowerShell version of a remote host:
> Invoke-Command -Computername server01 -Scriptblock {$PSVersionTable.psversion}
This can easily be extended to run against multiple remote hosts by bringing a list of computers into a variable, then using it with invoke-command
. For example:
> $computers = get-content c:\temp\computerlist.txt
> Invoke-Command -Computername $computers -Scriptblock {$PSVersionTable.psversion}
Summary
In this short article you have seen how you can list the PowerShell version on your local computer and how you can list the PowerShell version for one or more remote hosts.