How to find the Windows version from the PowerShell command line

前端 未结 25 1181
野的像风
野的像风 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:32

    As MoonStom says, [Environment]::OSVersion doesn't work properly on an upgraded Windows 8.1 (it returns a Windows 8 version): link.

    If you want to differentiate between Windows 8.1 (6.3.9600) and Windows 8 (6.2.9200), you can use (Get-CimInstance Win32_OperatingSystem).Version to get the proper version. However this doesn't work in PowerShell 2. So use this:

    $version = $null
    try {
        $version = (Get-CimInstance Win32_OperatingSystem).Version
    }
    catch {
        $version = [System.Environment]::OSVersion.Version | % {"{0}.{1}.{2}" -f $_.Major,$_.Minor,$_.Build}
    }
    

提交回复
热议问题