¿Cómo encontrar la versión de Windows desde la línea de comandos de PowerShell?


¿Cómo puedo encontrar qué versión de Windows estoy usando?

Estoy usando PowerShell 2.0 y probé:

PS C:\> ver
The term 'ver' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify tha
t the path is correct and try again.
At line:1 char:4
+ ver <<<< 
    + CategoryInfo          : ObjectNotFound: (ver:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

¿Cómo hago esto?

Author: Peter Mortensen, 2011-09-07

19 answers

Dado que tiene acceso a la biblioteca. NET, puede acceder a la OSVersion propiedad de la System.Environment clase para obtener esta información. Para el número de versión, existe la propiedad Version.

Por ejemplo,

PS C:\> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
6      1      7601   65536

Los detalles de las versiones de Windows se pueden encontrar aquí.

 111
Author: Jeff Mercado,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-02 10:32:31
  1. Para obtener el número de versión de Windows, como señala Jeff en su respuesta, use:

    [Environment]::OSVersion
    

    Vale la pena señalar que el resultado es de tipo [System.Version], así que es posible comprobar, por ejemplo, Windows 7 / Windows Server 2008 R2 y posterior con

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

    Sin embargo esto no le dirá si es Windows cliente o servidor, ni el nombre de la versión.

  2. Usar WMI Win32_OperatingSystem clase (siempre instancia única), para ejemplo:

    (Get-WmiObject -class Win32_OperatingSystem).Caption
    

    Devolverá algo como

    Microsoft® Windows Server® 2008 Standard

 89
Author: Richard,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:26:20
Get-WmiObject -Class Win32_OperatingSystem | ForEach-Object -MemberName Caption

O golfeado

gwmi win32_operatingsystem | % caption

Resultado

Microsoft Windows 7 Ultimate
 21
Author: Steven Penny,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-25 03:38:42

Desafortunadamente la mayoría de las otras respuestas no proporcionan información específica para Windows 10.

Windows 10 ha versiones de su propia: 1507, 1511, 1607, 1703, etc. Esto es lo que winver muestra.

Powershell:
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId

Command prompt (CMD.EXE):
Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseId

Ver también pregunta relacionada con el superusuario.

Como para otras versiones de Windows use systeminfo. Envoltura de Powershell:

PS C:\> systeminfo /fo csv | ConvertFrom-Csv | select OS*, System*, Hotfix* | Format-List


OS Name             : Microsoft Windows 7 Enterprise
OS Version          : 6.1.7601 Service Pack 1 Build 7601
OS Manufacturer     : Microsoft Corporation
OS Configuration    : Standalone Workstation
OS Build Type       : Multiprocessor Free
System Type         : x64-based PC
System Locale       : ru;Russian
Hotfix(s)           : 274 Hotfix(s) Installed.,[01]: KB2849697,[02]: KB2849697,[03]:...

Salida de Windows 10 para el mismo comando:

OS Name             : Microsoft Windows 10 Enterprise N 2016 LTSB
OS Version          : 10.0.14393 N/A Build 14393
OS Manufacturer     : Microsoft Corporation
OS Configuration    : Standalone Workstation
OS Build Type       : Multiprocessor Free
System Type         : x64-based PC
System Directory    : C:\Windows\system32
System Locale       : en-us;English (United States)
Hotfix(s)           : N/A
 15
Author: Anton Krouglov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-09 08:07:57

Esto le dará la versión completa de Windows (incluyendo el número de Revisión/Compilación) a diferencia de todas las soluciones anteriores:

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

Resultado:

10.0.10240.16392 (th1_st1.150716-1608)
 13
Author: Ihor Zenich,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-18 14:43:42

Estoy refinando una de las respuestas

Llegué a esta pregunta mientras intentaba hacer coincidir la salida de winver.exe:

Version 1607 (OS Build 14393.351)

Pude extraer la cadena de compilación con:

,((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name BuildLabEx).BuildLabEx -split '\.') | % {  $_[0..1] -join '.' }  

Resultado: 14393.351

Actualizado: Aquí hay un script ligeramente simplificado usando regex

(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").BuildLabEx -match '^[0-9]+\.[0-9]+' |  % { $matches.Values }
 7
Author: Fares,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-14 16:55:53

Si desea diferenciar entre Windows 8.1 (6.3.9600) y Windows 8 (6.2.9200) use

(Get-CimInstance Win32_OperatingSystem).Version 

Para obtener la versión adecuada. [Environment]::OSVersion no funciona correctamente en Windows 8.1 (devuelve una versión de Windows 8).

 6
Author: MoonStom,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-02 10:36:30

Desde PowerShell 5:

Get-ComputerInfo
Get-ComputerInfo -Property Windows*

Creo que este comando prácticamente intenta las 1001 formas diferentes hasta ahora descubiertas para recopilar información del sistema...

 5
Author: Schadowy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-25 14:43:55

Como dice MoonStom, [Environment]::OSVersion no funciona correctamente en un Windows 8.1 actualizado (devuelve una versión de Windows 8): link.

Si desea diferenciar entre Windows 8.1 (6.3.9600) y Windows 8 (6.2.9200), puede usar (Get-CimInstance Win32_OperatingSystem).Version para obtener la versión adecuada. Sin embargo, esto no funciona en PowerShell 2. Así que usa esto:

$version = $null
try {
    $version = (Get-CimInstance Win32_OperatingSystem).Version
}
catch {
    $version = [System.Environment]::OSVersion.Version | % {"{0}.{1}.{2}" -f $_.Major,$_.Minor,$_.Build}
}
 4
Author: mhu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-21 13:27:12

Uso:

Get-WmiObject -class win32_operatingsystem -computer computername | Select-Object Caption
 4
Author: Mac,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-02 10:34:41

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
}

Para visualización (ambas versiones):

"{0}  ({1})" -f $windows.Caption, $windows.Version 
 2
Author: Vince Ypma,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-01 03:06:49

Según Lars Fosdal - ¿Cómo encontrar la versión de Windows desde la línea de comandos de PowerShell?

PS C:\> Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer

Devuelve

WindowsProductName    WindowsVersion OsHardwareAbstractionLayer
------------------    -------------- --------------------------
Windows 10 Enterprise 1709           10.0.16299.371 

¿Se puede hacer esto remotamente? Por ejemplo, así:

Get-WMIObject –class win32_ComputerSystem –computername ProdBIG

Así que creo que planteo la pregunta incorrectamente.

¿Hay alguien para obtener esta información para otra computadora remota?

 2
Author: TWalker,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-17 13:22:16

(Get-ItemProperty-Path "HKLM: \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion" - Name BuildLabEx).BuildLabEx

 1
Author: Test,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-02 21:54:01

Esto le dará el número completo y CORRECTO (el mismo número de versión que encuentra cuando ejecuta winver.exe) versión de Windows (incluyendo número de revisión/compilación) REMOTAMENTE a diferencia de todas las otras soluciones (probadas en 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"
    }
}
 1
Author: PowerShellGirl,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-02 10:37:50

Si está tratando de descifrar la información que MS pone en su sitio de parches como https://technet.microsoft.com/en-us/library/security/ms17-010.aspx

Necesitarás un combo como:

$name=(Get-WmiObject Win32_OperatingSystem).caption $bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture $ver=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId Write-Host $name, $bit, $ver

Microsoft Windows 10 Inicio 64-bit 1703

 1
Author: Michael Joyce,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-28 13:59:53

Tomé los guiones de arriba y los ajusté un poco para llegar a esto:

$name=(Get-WmiObject Win32_OperatingSystem).caption
$bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture

$vert = " Version:"
$ver=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId

$buildt = " Build:"
$build= (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").BuildLabEx -match '^[0-9]+\.[0-9]+' |  % { $matches.Values }

$installd = Get-ComputerInfo -Property WindowsInstallDateFromRegistry

Write-host $installd
Write-Host $name, $bit, $vert, $ver, `enter code here`$buildt, $build, $installd

Para obtener un resultado como este:

Microsoft Windows 10 Home 64-bit Version: 1709 Build: 16299.431 @{WindowsInstallDateFromRegistry=18-01-01 2: 29: 11 AM}

Sugerencia: Apreciaría una mano eliminando el texto del prefijo de la fecha de instalación para que pueda reemplazarlo con un encabezado más legible.

 1
Author: Ron MVP,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-06-20 18:28:45

He buscado mucho para averiguar la versión exacta, porque el servidor WSUS muestra la versión incorrecta. Lo mejor es obtener la revisión de la clave del registro UBR.

    $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
Author: Ali,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-06-14 09:04:51
PS C:\> Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer

Devuelve

WindowsProductName    WindowsVersion OsHardwareAbstractionLayer
------------------    -------------- --------------------------
Windows 10 Enterprise 1709           10.0.16299.371 
 0
Author: Lars Fosdal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-10 09:22:31
$OSVersion = [Version](Get-ItemProperty -Path "$($Env:Windir)\System32\hal.dll" -ErrorAction SilentlyContinue).VersionInfo.FileVersion.Split()[0]

En Windows 10 devuelve: 10.0.10586.420

Luego puede usar la variable para acceder a las propiedades para la comparación granular

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

Además, puede comparar las versiones del sistema operativo utilizando la siguiente

If ([Version]$OSVersion -ge [Version]"6.1")
   {
       #Do Something
   }
 -1
Author: GraceSolutions,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-14 13:19:07