How to find the Windows version from the PowerShell command line

前端 未结 25 1085
野的像风
野的像风 2020-12-22 15:51

How do I find which Windows version I\'m using?

I\'m using PowerShell 2.0 and tried:

PS C:\\> ver
The term \'ver\' is not recognized as the name o         


        
25条回答
  •  一生所求
    2020-12-22 16:29

    $OSVersion = [Version](Get-ItemProperty -Path "$($Env:Windir)\System32\hal.dll" -ErrorAction SilentlyContinue).VersionInfo.FileVersion.Split()[0]
    

    On Windows 10 returns: 10.0.10586.420

    You can then use the variable to access properties for granular comparison

    $OSVersion.Major equals 10
    $OSVersion.Minor equals 0
    $OSVersion.Build equals 10586
    $OSVersion.Revision equals 420
    

    Additionally, you can compare operating system versions using the following

    If ([Version]$OSVersion -ge [Version]"6.1")
       {
           #Do Something
       }
    

提交回复
热议问题