Find Windows 11 Product Key

If you need to locate your Windows 11 Product Key

Use this script to identify your Windows 11 product key:

To run:

  • Unzip the file Get-WindowsProductKey.zip
  • At a command prompt type: powershell -ExecutionPolicy Bypass -File .\Get-WindowsProductKey.ps1

The source code is below – This comes without support and is to be used as-is.

<#
.SYNOPSIS
Retrieves the Windows product key from the current machine.
.DESCRIPTION
Checks the BIOS/UEFI-embedded OEM key first (common on machines that
came with Windows 11 pre-installed), then falls back to decoding the
key stored in the registry (DigitalProductId).
Note: Many modern PCs are activated via digital license (tied to your
Microsoft account or hardware ID) rather than a printed 25-character
key. If that's the case, this script won't find a traditional key,
and you can instead check activation status with: slmgr /xpr
.PARAMETER ExportPath
Optional. If provided, saves the result to a text file at this path.
.EXAMPLE
.\Get-WindowsProductKey.ps1
.EXAMPLE
.\Get-WindowsProductKey.ps1 -ExportPath "C:\Temp\productkey.txt"
.NOTES
Run this script as Administrator for reliable results.
Right-click PowerShell > "Run as administrator", then run the script.
#>
[CmdletBinding()]
param(
[string]$ExportPath
)
function Test-IsAdmin {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Get-WindowsProductKey {
[CmdletBinding()]
param()
# Method 1: OEM key embedded in firmware (most reliable on modern PCs)
try {
$oemKey = (Get-CimInstance -Query "SELECT * FROM SoftwareLicensingService" -ErrorAction Stop).OA3xOriginalProductKey
if ($oemKey) {
return [PSCustomObject]@{
Source     = "BIOS/UEFI (OEM embedded)"
ProductKey = $oemKey
}
}
}
catch {
Write-Verbose "Could not query SoftwareLicensingService: $_"
}
# Method 2: Decode key from registry (DigitalProductId)
try {
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$digitalProductId = (Get-ItemProperty -Path $regPath -Name "DigitalProductId" -ErrorAction Stop).DigitalProductId
$keyOffset = 52
$isWin8OrLater = ($digitalProductId[66] / 6) -band 1
$digitalProductId[66] = ($digitalProductId[66] -band 0xF7) -bor (($isWin8OrLater -band 2) * 4)
$chars = "BCDFGHJKMPQRTVWXY2346789"
$key = ""
for ($i = 24; $i -ge 0; $i--) {
$current = 0
for ($j = 14; $j -ge 0; $j--) {
$current = $current * 256 -bxor $digitalProductId[$j + $keyOffset]
$digitalProductId[$j + $keyOffset] = [math]::Floor($current / 24)
$current = $current % 24
}
$key = $chars[$current] + $key
if (($i % 5 -eq 0) -and ($i -ne 0)) {
$key = "-" + $key
}
}
return [PSCustomObject]@{
Source     = "Registry (DigitalProductId)"
ProductKey = $key
}
}
catch {
Write-Verbose "Could not retrieve product key from registry: $_"
}
return $null
}
# ---- Main ----
Write-Host ""
Write-Host "Windows Product Key Retriever" -ForegroundColor Cyan
Write-Host "==============================" -ForegroundColor Cyan
Write-Host ""
if (-not (Test-IsAdmin)) {
Write-Warning "This script is not running as Administrator. Results may be incomplete."
Write-Warning "For best results, right-click PowerShell and choose 'Run as administrator'."
Write-Host ""
}
$result = Get-WindowsProductKey
if ($result) {
$result | Format-List
Write-Host "Note: this is the OEM/registry key. If your PC is activated via a" -ForegroundColor DarkGray
Write-Host "Microsoft account or digital license, this may not match what's" -ForegroundColor DarkGray
Write-Host "actually validating your install." -ForegroundColor DarkGray
if ($ExportPath) {
try {
"Source: $($result.Source)`nProductKey: $($result.ProductKey)`nRetrieved: $(Get-Date)" |
Out-File -FilePath $ExportPath -Encoding UTF8
Write-Host ""
Write-Host "Saved to $ExportPath" -ForegroundColor Green
}
catch {
Write-Warning "Could not save to $ExportPath : $_"
}
}
}
else {
Write-Host "No traditional product key was found on this machine." -ForegroundColor Yellow
Write-Host "This usually means Windows is activated via digital license" -ForegroundColor Yellow
Write-Host "(tied to your Microsoft account or hardware), not a key string." -ForegroundColor Yellow
Write-Host ""
Write-Host "To check activation status instead, run:" -ForegroundColor Yellow
Write-Host "    slmgr /xpr" -ForegroundColor White
}
Write-Host ""
Scroll to Top