How to find the Windows version from the PowerShell command line

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

    If you want to differentiate between Windows 8.1 (6.3.9600) and Windows 8 (6.2.9200) use

    (Get-CimInstance Win32_OperatingSystem).Version 
    

    to get the proper version. [Environment]::OSVersion doesn't work properly in Windows 8.1 (it returns a Windows 8 version).

    0 讨论(0)
  • 2020-12-22 16:21

    I searched a lot to find out the exact version, because WSUS server shows the wrong version. The best is to get revision from UBR registry KEY.

        $WinVer = New-Object –TypeName PSObject
    $WinVer | Add-Member –MemberType NoteProperty –Name Major –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' CurrentMajorVersionNumber).CurrentMajorVersionNumber
    $WinVer | Add-Member –MemberType NoteProperty –Name Minor –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' CurrentMinorVersionNumber).CurrentMinorVersionNumber
    $WinVer | Add-Member –MemberType NoteProperty –Name Build –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' CurrentBuild).CurrentBuild
    $WinVer | Add-Member –MemberType NoteProperty –Name Revision –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' UBR).UBR
    $WinVer
    
    0 讨论(0)
  • 2020-12-22 16:21

    [solved]

    #copy all the code below:
    #save file as .ps1 run and see the magic
    
     Get-WmiObject -Class Win32_OperatingSystem | ForEach-Object -MemberName Caption
     (Get-CimInstance Win32_OperatingSystem).version
    
    
    #-------------comment-------------#
    #-----finding windows version-----#
    
    $version= (Get-CimInstance Win32_OperatingSystem).version
    $length= $version.Length
    $index= $version.IndexOf(".")
    [int]$windows= $version.Remove($index,$length-2)  
    $windows
    #-----------end------------------#
    #-----------comment-----------------#
    
    0 讨论(0)
  • 2020-12-22 16:24
    Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer
    

    returns

    WindowsProductName    WindowsVersion OsHardwareAbstractionLayer
    ------------------    -------------- --------------------------
    Windows 10 Enterprise 1709           10.0.16299.371 
    
    0 讨论(0)
  • 2020-12-22 16:24

    Windows PowerShell 2.0:

    $windows = New-Object -Type PSObject |
               Add-Member -MemberType NoteProperty -Name Caption -Value (Get-WmiObject -Class Win32_OperatingSystem).Caption -PassThru |
               Add-Member -MemberType NoteProperty -Name Version -Value [Environment]::OSVersion.Version                     -PassThru
    

    Windows PowerShell 3.0:

    $windows = [PSCustomObject]@{
        Caption = (Get-WmiObject -Class Win32_OperatingSystem).Caption
        Version = [Environment]::OSVersion.Version
    }
    

    For display (both versions):

    "{0}  ({1})" -f $windows.Caption, $windows.Version 
    
    0 讨论(0)
  • 2020-12-22 16:29

    This will give you the full version of Windows (including Revision/Build number) unlike all the solutions above:

    (Get-ItemProperty -Path c:\windows\system32\hal.dll).VersionInfo.FileVersion
    

    Result:

    10.0.10240.16392 (th1_st1.150716-1608)
    
    0 讨论(0)
提交回复
热议问题