Created
January 22, 2026 01:17
-
-
Save MtkN1/7998d41df4af2adcd3094c02fc39691b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Windows/Office バージョンレポート(Windows 10/11 + Microsoft 365 Apps / Click-to-Run 想定) | |
| # 出力例: | |
| # Windows バージョン: Windows 11 25H2 (ビルド: 26220.7623) | |
| # Office バージョン: 2512 (ビルド: 19530.20184) | |
| Set-StrictMode -Version Latest | |
| $ErrorActionPreference = "Stop" | |
| function Get-WindowsVersionReport { | |
| $regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | |
| $os = Get-ItemProperty -Path $regPath -ErrorAction Stop | |
| $displayVersion = $null | |
| if ($os.PSObject.Properties.Name -contains "DisplayVersion") { $displayVersion = $os.DisplayVersion } | |
| if (-not $displayVersion -and ($os.PSObject.Properties.Name -contains "ReleaseId")) { $displayVersion = $os.ReleaseId } | |
| if (-not $displayVersion) { $displayVersion = "(不明)" } | |
| $currentBuild = $null | |
| if ($os.PSObject.Properties.Name -contains "CurrentBuildNumber") { $currentBuild = $os.CurrentBuildNumber } | |
| elseif ($os.PSObject.Properties.Name -contains "CurrentBuild") { $currentBuild = $os.CurrentBuild } | |
| if (-not $currentBuild) { throw "Windows の CurrentBuild( Number) を取得できませんでした。" } | |
| $ubr = $null | |
| if ($os.PSObject.Properties.Name -contains "UBR") { $ubr = $os.UBR } | |
| $buildFull = if ($null -ne $ubr -and "$ubr" -ne "") { "$currentBuild.$ubr" } else { "$currentBuild" } | |
| # 目標出力に合わせて「Windows 10/11」を推定(ProductName は環境により紛らわしい値になることがあるため) | |
| $buildInt = [int]$currentBuild | |
| $winName = if ($buildInt -ge 22000) { "Windows 11" } else { "Windows 10" } | |
| return "Windows バージョン: {0} {1} (ビルド: {2})" -f $winName, $displayVersion, $buildFull | |
| } | |
| function Get-OfficeC2RBuildInfo { | |
| $candidatePaths = @( | |
| "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration", | |
| "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration" | |
| ) | |
| foreach ($p in $candidatePaths) { | |
| if (Test-Path $p) { | |
| $cfg = Get-ItemProperty -Path $p -ErrorAction Stop | |
| $raw = $null | |
| if ($cfg.PSObject.Properties.Name -contains "VersionToReport") { $raw = $cfg.VersionToReport } | |
| if (-not $raw -and ($cfg.PSObject.Properties.Name -contains "ClientVersionToReport")) { $raw = $cfg.ClientVersionToReport } | |
| if ($raw) { | |
| # raw は例: 16.0.19530.20184 | |
| $v = [version]$raw | |
| $buildShort = if ($v.Revision -ge 0) { "$($v.Build).$($v.Revision)" } else { "$($v.Build)" } | |
| $channel = $null | |
| if ($cfg.PSObject.Properties.Name -contains "UpdateChannel") { $channel = $cfg.UpdateChannel } | |
| return [pscustomobject]@{ | |
| RawVersion = $raw | |
| BuildShort = $buildShort # 例: 19530.20184 | |
| UpdateChannel = $channel | |
| RegPath = $p | |
| } | |
| } | |
| } | |
| } | |
| return $null | |
| } | |
| function Resolve-OfficeYYMMFromBuild { | |
| param( | |
| [Parameter(Mandatory=$true)][string]$BuildShort, | |
| [int]$TimeoutSec = 10 | |
| ) | |
| # Microsoft Learn の「日付別更新履歴」から Build → Version(YYMM) を逆引き | |
| $url = "https://learn.microsoft.com/en-us/officeupdates/update-history-microsoft365-apps-by-date" | |
| try { | |
| $resp = Invoke-WebRequest -Uri $url -TimeoutSec $TimeoutSec -UseBasicParsing | |
| $html = $resp.Content | |
| $b = [regex]::Escape($BuildShort) | |
| $m = [regex]::Match($html, "Version\s+(?<ver>\d{4})\s*\(Build\s+$b\)", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) | |
| if ($m.Success) { return $m.Groups["ver"].Value } | |
| return $null | |
| } | |
| catch { | |
| return $null | |
| } | |
| } | |
| # ---- main ---- | |
| try { | |
| $winLine = Get-WindowsVersionReport | |
| $officeInfo = Get-OfficeC2RBuildInfo | |
| if (-not $officeInfo) { | |
| $officeLine = "Office バージョン: (未検出)" | |
| } else { | |
| $yymm = Resolve-OfficeYYMMFromBuild -BuildShort $officeInfo.BuildShort | |
| if (-not $yymm) { $yymm = "(不明)" } | |
| $officeLine = "Office バージョン: {0} (ビルド: {1})" -f $yymm, $officeInfo.BuildShort | |
| } | |
| Write-Output $winLine | |
| Write-Output $officeLine | |
| } | |
| catch { | |
| Write-Error $_ | |
| exit 1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment