How to find the Windows version from the PowerShell command line

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

    This will give you the full and CORRECT (the same version number that you find when you run winver.exe) version of Windows (including revision/build number) REMOTELY unlike all the other solutions (tested on Windows 10):

    Function Get-OSVersion {
    Param($ComputerName)
        Invoke-Command -ComputerName $ComputerName -ScriptBlock {
            $all = @()
            (Get-Childitem c:\windows\system32) | ? Length | Foreach {
    
                $all += (Get-ItemProperty -Path $_.FullName).VersionInfo.Productversion
            }
            $version = [System.Environment]::OSVersion.Version
            $osversion = "$($version.major).0.$($version.build)"
            $minor = @()
            $all | ? {$_ -like "$osversion*"} | Foreach {
                $minor += [int]($_ -replace".*\.")
            }
            $minor = $minor | sort | Select -Last 1
    
            return "$osversion.$minor"
        }
    }
    

提交回复
热议问题