You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过PowerShell区分Windows 10与Windows 11操作系统

如何用PowerShell区分Windows 10和Windows 11

在Windows 10和Windows 11中,使用[Environment]::OSVersion.Version、读取hal.dll文件版本或Win32_OperatingSystem的Version属性时,都会返回10.0作为主版本号和次版本号,无法直接区分系统版本。以下是几种可靠的区分方法:

  • 通过系统版本名称直接识别
    利用Win32_OperatingSystem类的Caption属性,该属性会直接返回包含明确系统名称的字符串:

    $osCaption = (Get-CimInstance -Class Win32_OperatingSystem).Caption
    if ($osCaption -match "Windows 11") {
        Write-Host "当前系统是Windows 11"
    } elseif ($osCaption -match "Windows 10") {
        Write-Host "当前系统是Windows 10"
    }
    
  • 通过系统构建版本号区分
    Windows 10的构建版本号范围为1507至19045,Windows 11的构建版本号从22000开始(后续更新如22H2为22621等),可通过读取BuildNumber属性判断:

    $buildNumber = (Get-CimInstance -Class Win32_OperatingSystem).BuildNumber
    if ($buildNumber -ge 22000) {
        Write-Host "当前系统是Windows 11"
    } elseif ($buildNumber -ge 1507 -and $buildNumber -le 19045) {
        Write-Host "当前系统是Windows 10"
    }
    
  • 通过注册表项识别
    读取系统注册表中存储的产品名称字段,直接获取系统版本信息:

    $productName = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName
    if ($productName -match "Windows 11") {
        Write-Host "当前系统是Windows 11"
    } elseif ($productName -match "Windows 10") {
        Write-Host "当前系统是Windows 10"
    }
    

内容的提问来源于stack exchange,提问作者YorSubs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 22:55:18