How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all?
Use $PSVersionTable.PSVersion
to determine the engine version. If the variable does not exist, it is safe to assume the engine is version 1.0
.
Note that $Host.Version
and (Get-Host).Version
are not reliable - they reflect the version of the host only, not the engine. PowerGUI, PowerShellPLUS, etc. are all hosting applications, and they will set the host's version to reflect their product version — which is entirely correct, but not what you're looking for.
PS C:\> $PSVersionTable.PSVersion Major Minor Build Revision ----- ----- ----- -------- 4 0 -1 -1
I would use either Get-Host or $PSVersionTable. As Andy Schneider points out, $PSVersionTable
doesn't work in version 1; it was introduced in version 2.
get-host Name : ConsoleHost Version : 2.0 InstanceId : d730016e-2875-4b57-9cd6-d32c8b71e18a UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : en-GB CurrentUICulture : en-US PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace $PSVersionTable Name Value ---- ----- CLRVersion 2.0.50727.4200 BuildVersion 6.0.6002.18111 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0} SerializationVersion 1.1.0.1 PSRemotingProtocolVersion 2.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With