Skip to content

Instantly share code, notes, and snippets.

@Diagg
Created October 12, 2021 22:08
Show Gist options
  • Select an option

  • Save Diagg/756d7564f342b8cfcae26ccead235f08 to your computer and use it in GitHub Desktop.

Select an option

Save Diagg/756d7564f342b8cfcae26ccead235f08 to your computer and use it in GitHub Desktop.
how to retrieve meaningful (like 21H2) build number from the internet. (Support Windows 10 and 11)
# OSFriendlyBuild.ps1 by Diagg/OSD-Couture.com
$OSBuild = @{}
$BuildNumber = (Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion').CurrentBuild
IF ([int]($BuildNumber) -lt 22000){$HTML = Invoke-RestMethod 'https://docs.microsoft.com/en-us/windows/release-health/release-information'}
else {$HTML = Invoke-RestMethod 'https://docs.microsoft.com/en-us/windows/release-health/windows11-release-information'}
$Pattern = '<strong>(?<version>.*)<\/strong>'
$AllMatches = ($HTML | Select-String $Pattern -AllMatches).Matches
($AllMatches.Groups | Where-Object {$_.name -eq 'version'}).value -replace "Version " -replace "\(RTM\) " -replace "\(original release\) " -replace "\(OS build" -replace "\)"| ForEach-Object {$Htbl = $_ -split " "; $OSBuild[$Htbl[2]] = $Htbl[0]}
Try {[System.Environment]::SetEnvironmentVariable('OSBUILD',$OSBuild[$buildnumber],'Machine')}
Catch {[System.Environment]::SetEnvironmentVariable('OSBUILD',$OSBuild[$buildnumber],'User')}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment