PowerShell – PowerShell Installed/Compatible Version

|

Possibly one of my important commands is to find out what version I have available on the computer.

There are various ways to get this and some are rather long and arduous in comparison

clear

Write-Output "Get-Host (Really Only For 1.0, use once of the two below instead)"
     get-host | Format-Table name, version -AutoSize

Write-Output "`nPSVersionTable.PSVersion (If All you care about is the version)"
     $PSVersionTable.PSVersion

Write-Output "`nGet-PSVersion"
     function Get-PSVersion {
          if (test-path variable:psversiontable) {$psversiontable.psversion} else {[version]"1.0.0.0"}
     }
     Get-PSVersion

Write-Output "`nPSVersionTable"
     $PSVersionTable | format-table -AutoSize

Write-Output "`nPSVersionTable - Custom Hash Table"
     $system = @{
          "PS Version" = $PSVersionTable.PSVersion
          "PS Compatible Versions" = $PSVersionTable.PSCompatibleVersions
     }

     $system | format-table -AutoSize -HideTableHeaders

This will display something like this:

Get-Host (Really Only For 1.0, use once of the two below instead)
     Name                        Version
     ----                        -------
     Windows PowerShell ISE Host 4.0    

PSVersionTable.PSVersion (If All you care about is the version)
     Major Minor Build Revision
     ----- ----- ----- --------
     4     0     -1    -1      

Get-PSVersion
     4     0     -1    -1      

PSVersionTable
     Name                      Value               
     ----                      -----               
     PSVersion                 4.0                 
     WSManStackVersion         3.0                 
     SerializationVersion      1.1.0.1             
     CLRVersion                4.0.30319.42000     
     BuildVersion              6.3.9600.16406      
     PSCompatibleVersions      {1.0, 2.0, 3.0, 4.0}
     PSRemotingProtocolVersion 2.2                 

PSVersionTable - Custom Hash Table
     PS Version             4.0                 
     PS Compatible Versions {1.0, 2.0, 3.0, 4.0}
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.