Checking the Powershell version is a requirement for an upgrade cycle. How can I programatically extract the Powershell version and create a report . This would allow me to include a check before I execute some code?
Answer: The Powershell version can be extracted from the $PSVersionTable variable. The $PSVersionTable contains other information which I’ve included in this output.
PS > $PSVersionTable Name Value ---- ----- CLRVersion 2.0.50727.5485 BuildVersion 6.1.7601.17514 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0} SerializationVersion 1.1.0.1 PSRemotingProtocolVersion 2.1
To get only the PSVersion use $PSVersionTable.PSVersion