How to find the Windows version from the PowerShell command line

前端 未结 25 1092
野的像风
野的像风 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条回答
  •  旧时难觅i
    2020-12-22 16:32

    1. To get the Windows version number, as Jeff notes in his answer, use:

      [Environment]::OSVersion
      

      It is worth noting that the result is of type [System.Version], so it is possible to check for, say, Windows 7/Windows Server 2008 R2 and later with

      [Environment]::OSVersion.Version -ge (new-object 'Version' 6,1)
      

      However this will not tell you if it is client or server Windows, nor the name of the version.

    2. Use WMI's Win32_OperatingSystem class (always single instance), for example:

      (Get-WmiObject -class Win32_OperatingSystem).Caption
      

      will return something like

      Microsoft® Windows Server® 2008 Standard

提交回复
热议问题