UFO ET IT

PowerShell 명령줄에서 윈도우즈 버전을 찾는 방법

ufoet 2023. 4. 8. 14:34
반응형

PowerShell 명령줄에서 윈도우즈 버전을 찾는 방법

사용 중인 Windows 버전을 찾으려면 어떻게 해야 합니까?

PowerShell 2.0을 사용하고 있으며 다음을 시도했습니다.

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

이거 어떻게 해?

에 액세스 할 수 있습니다.NET 라이브러리에서는 클래스 속성에 액세스하여 이 정보를 얻을 수 있습니다.버전 번호에는,Version★★★★★★★★★★★★★★★★★★.

예를들면,

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

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

Windows 버전에 대한 자세한 내용은 여기를 참조하십시오.

  1. Jeff가 회답한 대로, Windows 버전 번호를 취득하려면 , 다음을 사용합니다.

    [Environment]::OSVersion
    

    결과가 유형이기 때문에 예를 들어 Windows 7/Windows Server 2008 R2 이후를 확인할 수 있습니다.

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

    그러나 클라이언트 또는 서버 Windows인지 버전 이름은 알 수 없습니다.

  2. WMI 클래스(항상 단일 인스턴스) 사용:

    (Get-WmiObject -class Win32_OperatingSystem).Caption
    

    같은 것을 돌려줄 것이다

    Microsoft®Windows Server®2008 Standard

유감스럽게도 다른 답변의 대부분은 Windows 10에 고유한 정보를 제공하지 않습니다.

Windows 10에는 1507, 1511, 1607, 1703 등의 독자적인 버전이 있습니다.이런 거winver참조해 주세요.

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

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

슈퍼 유저에 관한 관련 질문도 참조해 주세요.

를 사용합니다.systeminfo 래퍼 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]:...

같은 명령어의 Windows 10 출력:

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
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer

돌아온다

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

위의 모든 솔루션과 달리 Windows 풀 버전(리비전/빌드 번호 포함)이 표시됩니다.

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

결과:

10.0.10240.16392 (th1_st1.150716-1608)

PowerShell 5 이후:

Get-ComputerInfo
Get-ComputerInfo -Property Windows*

이 명령어는 시스템 정보를 수집하기 위해 지금까지 발견된 1001개의 다양한 방법을 시도하고 있습니다.

Windows 8.1(6.3.9600)과 Windows 8(6.2.9200)을 구별하려면

(Get-CimInstance Win32_OperatingSystem).Version 

을 사용법 [Environment]::OSVersionWindows 8.1 에 액세스 할 수 있다(Windows 8 에 액세스 할 수 있다).

대답들 중 하나를 다듬고 있어

winver의 출력을 대조하는 중에 이 질문에 도달했습니다.실행:

Version 1607 (OS Build 14393.351)

빌드 문자열을 추출할 수 있었습니다.

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

★★★★★14393.351

갱신일 :다음은 regex를 사용한 간단한 스크립트입니다.

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

MS가 패치 적용 사이트(https://technet.microsoft.com/en-us/library/security/ms17-010.aspx)에 올린 정보를 해독하는 경우

다음과 같은 조합이 필요합니다.

$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 Home 64비트 1703

위의 스크립트를 조금 수정하여 이 방법을 생각해 냈습니다.

$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

다음과 같은 결과를 얻으려면:

Microsoft Windows 10 Home 64비트 버전: 1709 빌드: 16299.431 @{WindowsInstallDateFromRegistry=18-01-01 2:29:11 AM}

힌트: 프리픽스 텍스트를 읽기 쉬운 헤더로 대체할 수 있도록 설치 날짜에서 삭제해 주시면 감사하겠습니다.

Windows 10 1809의 PowerShell v5에서 winver.exe와 동일한 출력을 생성하려면 다음 절차를 따릅니다.

$Version = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\'
"Version $($Version.ReleaseId) (OS Build $($Version.CurrentBuildNumber).$($Version.UBR))"

다른 답변 외에 PowerShell을 사용하여 얻을 수 있는 몇 가지 유용한 정보를 소개합니다.

PowerShell을 통한 OS 및 하드웨어 정보 조회:

일반 OS(운영 체제) 쿼리정보:

OS 이름을 표시하는 가장 빠른 방법:

cmd ?

#Get-Computer 사용방법정보:

Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer

#Get-Wmi Object 사용:

$name=(Get-WmiObject Win32_OperatingSystem).caption
$bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture
$ver=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
Write-Host " OS-Name: `t $name `n Architct: `t $bit  `n Release: `t $ver" 

메이저 마이너 버전 정보를 나열하려면:

[System.Environment]::OSVersion.Version 

HostName 쿼리 중:

$Env:ComputerName

또는

hostname    #cmd command

IP 주소를 있는 「를 들면 「IP」, 「ping」)를 합니다.ping /a <your_ip_address>의 첫 「hostname이됩니다. 호스트명

현재(로그인) 사용자 쿼리 중:

whoami    #cmd command

또는

[System.Security.Principal.WindowsIdentity]::GetCurrent().Name 

매핑된 드라이브 쿼리: 매핑된 드라이브 나열 - WMI 사용:

Get-WmiObject -Class Win32_LogicalDisk | Format-Table 

또는

wmic logicaldisk get name       #list just logical-drive letters

논리 드라이브 정보를 나열하려면:FreeSpace, 공급자(실제 네트워크 위치), 크기 및 볼륨 이름:

wmic logicaldisk list brief

매핑된 드라이브 나열 - [DriveInfo] 클래스 사용:

[System.IO.DriveInfo]::GetDrives()

이동식 드라이브 목록:

$drives = [System.IO.DriveInfo]::GetDrives()
$r = $drives | Where-Object { $_.DriveType -eq 'Removable' -and $_.IsReady }
if ($r) {
    return @($r)[-1]
}

디스크 용량, 용량 및 볼륨 유형 조회

Invoke-Command -ComputerName S1 {Get-PSDrive C} | Select-Object PSComputerName,Used,Free 

빈 공간:

(Get-PSDrive C).Free

OR (GB 단위)

[Math]::Floor(((Get-PSDrive C).Free /[Math]::Pow(2, 30)*10)) /10

사용된 공간:

(Get-PSDrive C).Used

OR(GB 단위의 사용 공간)

[Math]::Floor(((Get-PSDrive C).Used /[Math]::Pow(2, 30)*10)) /10

총 용량 표시: (GB 단위)

$totalSpace = ((Get-PSDrive C).Used + (Get-PSDrive C).Free)/(1024*1024*1024)
OR
$totalSpace = ((Get-PSDrive C).Used + (Get-PSDrive C).Free)/[Math]::Pow(2, 30)

반올림된 값:

[Math]::Floor($totalSpace*10) / 10
OR
[Math]::Round($totalSpace,1)

메인보드 정보 쿼리 중:

wmic baseboard get product,Manufacturer,version,serialnumber

디스크 볼륨 쿼리(디스크 파티션) 정보: Get-Volume는 스토리지 드라이브의 파티션에 대한 정보를 반환합니다.

Get-Volume                 # All partitions
Get-Volume -DriveLetter C  # Specific partition

#파일 시스템 유형:

Get-Volume -DriveLetter C | select FileSystem
(Get-Volume -DriveLetter C).FileSystem

#표준 크기:

Get-Volume -DriveLetter C | select Size
OR (in GB)
[Math]::Floor(((Get-Volume -DriveLetter C).Size/[Math]::Pow(2, 30)*10)) /10

메모리 쿼리/RAM 쿼리

Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum
OR (in GB)
$memory = (Get-WmiObject Win32_PhysicalMemory | Measure -Property Capacity -Sum).Sum
$memory = [Math]::Floor(($memory/[Math]::Pow(2, 30)*10)) /10
$memory.ToString() + " gb"

#주파수/속도를 포함한 쿼리 RAM:

Get-CimInstance win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber –autosize

앞에서 설명한 바와 같이 이 답변은 질문을 조금 넘어섰지만 PowerShell을 사용하여 추가 OS 또는 하드웨어 정보를 원하는 사용자에게 유용할 수 있습니다.

말처럼 MoonStom은 말 as as as as as as as as as [Environment]::OSVersion업그레이드된 Windows 8.1에서 제대로 작동하지 않음(Windows 8 버전을 반환함): 링크

8.18(6는, 8.1(6.3.9600) 「Windows 8(6.2.9200)」를 사용할 수 .(Get-CimInstance Win32_OperatingSystem).Version을 사용법PowerShell 2 에에에 。이것을 사용해 주세요.

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

용도:

Get-WmiObject -class win32_operatingsystem -computer computername | Select-Object Caption

다음과 같이 간단해야 합니다.

Get-ComputerInfo  | select windowsversion

이것은 실로 긴 줄거리이며, 아마도 정답이 맞다고 해도 근본적인 문제가 해결되지 않기 때문일 것이다.우연히 이 사이트를 발견했습니다.버전빌드 번호.Microsoft Windows의 세계에 대해 알기 쉬운 개요를 제공합니다.

어떤 윈도 OS를 취급하고 있는지 알고 싶기 때문에 전체 버전은 제쳐두고 Build Number에 초점을 맞췄습니다.빌드 번호는 다음 중 하나를 통해 얻을 수 있습니다.

([Environment]::OSVersion.Version).Build

또는 다음과 같이 입력합니다.

(Get-CimInstance Win32_OperatingSystem).buildNumber

어느 쪽을 선택하든 선택은 네 몫이다.거기서부터 다음과 같은 일을 할 수 있었습니다.

    switch ((Get-CimInstance Win32_OperatingSystem).BuildNumber) 
{
    6001 {$OS = "W2K8"}
    7600 {$OS = "W2K8R2"}
    7601 {$OS = "W2K8R2SP1"}    
    9200 {$OS = "W2K12"}
    9600 {$OS = "W2K12R2"}
    14393 {$OS = "W2K16v1607"}
    16229 {$OS = "W2K16v1709"}
    default { $OS = "Not Listed"}

}
Write-Host "Server system: $OS" -foregroundcolor Green

주의: 보시는 바와 같이 위의 내용은 서버 시스템에만 사용했지만 워크스테이션에 쉽게 적용하거나 둘 다 지원하도록 현명하게 확장할 수 있습니다.하지만 그건 당신에게 맡기겠어요.

즐겁게 즐기세요!

당신들은 너무 열심히 하고 있어요.이것은 Enter-PSSession을 사용하는 로컬세션 또는 리모트세션과 함께 동작합니다.해 보세요.

다음과 같이 입력하기만 하면 됩니다.

cmd ?

Microsoft Windows [버전 10.0.19042.1237]

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
}

디스플레이(양쪽 버전):

"{0}  ({1})" -f $windows.Caption, $windows.Version 
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Update\TargetingInfo\Installed\Client.OS.rs2.amd64').version

Tim의 이전 답변을 바탕으로 이 특정 장소의 좋은 점은 이 부동산이 이미 제가 선호하는 포맷으로 되어 있다는 것입니다.

오늘날에는 보다 공식적인 방법으로 다음을 사용하고 있습니다.

Get-ComputerInfo | select WindowsProductName, OsOperatingSystemSKU, OsName | fl

# <output>
# WindowsProductName   : Windows 10 Home
# OsOperatingSystemSKU : WindowsHome
# OsName               : Microsoft Windows 10 Home

다른 항목을 찾으려면 다음 목록에서 확인하십시오.

(Get-CimInstance Win32_OperatingSystem) | select *

# ...
# and: 
(Get-CimInstance Win32_OperatingSystem).Caption

# Microsoft Windows 10 Home

WSUS 서버가 잘못된 버전을 표시하기 때문에 정확한 버전을 찾기 위해 많이 검색했습니다.가장 좋은 방법은 UBR 레지스트리 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
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name BuildLabEx).BuildLabEx

Winver와 동등한 Powershell

모든 버전의 Windows 10에서 20h2까지 동작 가능.빠르고 복잡하지 않음*

function Get-WinVer() {
    $win_release = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").displayversion
    if (!($win_release)) {
        $win_release = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId}
    $win_release
}
Get-WinVer

은 정확히 있다.winver.exe에 [Version]를 나타냅니다.

이 코드를 작성하기 위해 그렇게 많이 읽을 필요가 없을 것이라고 예상했고, 22h1(또는 그 당시 이름이 무엇이든) 동안 코드를 수정할 필요가 없었으면 합니다.


*: Microsoft는 확실히 그것을 필요 이상으로 복잡하게 만들었습니다.

다른 모든 솔루션(Windows 10에서 테스트 완료)과는 달리 Windows의 풀버전(winver.exe를 실행했을 때와 같은 버전 번호)이 리모트로 표시됩니다.

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"
    }
}

Windows Powershell을 사용하면 다음과 같은 방법으로 필요한 데이터를 얻을 수 있습니다.

설명:

(Get-WmiObject -class Win32_OperatingSystem).Caption

릴리스 ID:

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

버전:

(Get-CimInstance Win32_OperatingSystem).version

[아쉬움]

#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-----------------#

OSVersion을 체크함으로써 이와 같은 기능을 사용할 수도 있습니다.버전메이저:

IF ([System.Environment]::OSVersion.Version.Major -ge 10) {Write-Host "Windows 10 or above"}
IF ([System.Environment]::OSVersion.Version.Major -lt 10) {Write-Host "Windows 8.1 or below"}

HKLM\SOFTWARE\Microsoft\Windows NT\Current Version\업데이트\TargetingInfo\설치\클라이언트OS.rs2.amd64\Version 'Windows 10 클라이언트용'

HKLM\SOFTWARE\Microsoft\Windows NT\Current Version\업데이트\TargetingInfo\인스톨 완료\Server.OS.amd64\Version '서버 OS용'

그냥 작은 대본을 완성하고 싶었어요.이전에 답변한 스위치 버전을 사용하여 자세히 설명했습니다.우리에게 익숙한 친근한 이름을 줄 수 있는 곳은 없습니다.Windows 10 1909 또는 Windows 10 20H2.그래서 우리는 그것들을 수동으로 프로그램해야 합니다.

$osversion = (Get-CimInstance -class Win32_OperatingSystem).Caption
$buildnumber = (Get-CimInstance Win32_OperatingSystem).BuildNumber
if($osversion -match "Windows 10")
{   
    switch ($buildnumber) 
    { 
        10240 {$OS = "Windows 10 1507"}
        10586 {$OS = "Windows 10 1511"}
        14393 {$OS = "Windows 10 1607"}
        15063 {$OS = "Windows 10 1703"}
        16299 {$OS = "Windows 10 1709"}
        17134 {$OS = "Windows 10 1803"}
        17763 {$OS = "Windows 10 1809"}
        18362 {$OS = "Windows 10 1903"}
        18363 {$OS = "Windows 10 1909"}
        19041 {$OS = "Windows 10 20H1"}
        19042 {$OS = "Windows 10 20H2"}
        19043 {$OS = "Windows 10 21H1"}
        default { $OS = "Not Listed"}
    }
}
if($osversion -match "Windows Server")
{
    switch ($buildnumber) 
    {
        3790 {$OS = "Windows Server 2003 R2"}
        6001 {$OS = "Windows Server 2008"}
        7600 {$OS = "Windows Server 2008 SP1"}
        7601 {$OS = "Windows Server 2008 R2"}    
        9200 {$OS = "Windows Server 2012"}
        9600 {$OS = "Windows Server 2012 R2"}
        14393 {$OS = "Windows Server 2016"}
        17763 {$OS = "Windows Server 2019"}
    }
}
Write-Host "Server system: $OS | $osversion | $buildnumber" -foregroundcolor Green

여러 대의 PC를 한 번에 스캔하고 싶은 경우invoke-command또는new-pssession부디 참고하세요Get-WMIObject감가상각되어 로 대체된다.get-ciminstance

Windows 2003 R2 이전 버전을 사용하는 경우 나중에 예를 들어 드릴 수 있습니다.정지 새로운 OS로의 이행이 정지.

powershell의 C:\ 프롬프트 또는 cmd 프롬프트 창에서 systeminfo에 OS 이름 버전 설정 제조업체 및 기타 정보가 표시됩니다.

언급URL : https://stackoverflow.com/questions/7330187/how-to-find-the-windows-version-from-the-powershell-command-line

반응형