微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

4 Ways to Check the Current PowerShell Version on Your PC

Introduction

If you are reading this guide because you want to learn how to find the PowerShell version on your computer,you are in the right place!

This guide details 4 ways you can check the version of PowerSell on your computer.

4 Ways to Get the PowerShell Version on your PC

If you want to determine the version of PowerShell on your computer,use one of the methods/commands discussed below:

Method 1: Get PowerShell Version with $PsversionTable Automatic Variable

copy and paste the command below into a PowerShell console and press Enter

$PsversionTable

Here is the result

 

My current PS version is 5.1.17134.858 but the result contains other information which you may not need.

To display just the version number,use the command below

$PsversionTable.Psversion

Here is the result

 

The last command provides a bit more information. We Now kNow that 5,1,17134,858 represents Major,Minor,Build and Revision numbers.

To display just the Major number,use this command:

$PsversionTable.Psversion.Major

Method 2: Get PS Version with Get-Variable PsversionTable Command

You can also get your PS version using the command below:

powershell -command "(Get-Variable PsversionTable -ValueOnly).Psversion"

The result is the same as the last command

 

Method 3: Get PowerShell Version with Get-Host Command

Here is another command that will give your PS version

Get-Host

The command returned a result with the full version details

 

If you want just the version number,you can use any of the 3 commands below:

Get-Host | Select-Object Version

This command will expand the version numbers

Get-Host | Select-Object -ExpandProperty Version

(Get-Host).Version

The last two commands product the same result. Here are the results of the 3 commands

 

If you want to display just the Major PowerShell version,use this command:

(Get-Host).Version.Major

Method 4: Get Powershell Version with $Host Automatic Variable

To use this method type the following command into a PowerShell prompt. Then press Enter.

$Host

Below is the result of the command in PowerShell

 

As you can see,the result is the same as using the Get-Host Command

Here is an example:

 

Conclusion

There are so many reasons you may want to determine the PowerShell version. It may be that you wrote a script that requires a minimum version to run successfully. No matter your reason,I hope it met your need!

If you have any question or want to leave a comment,use the “Leave a Reply” form at the end of this script. Alternatively,you Could share your experience working with PowerShell versions.

 

原文地址:https://blog.csdn.net/allway2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐