Get key and Activate
$key = Get-WmiObject -Class SoftwareLicensingService | Select-Object OA3xOriginalProductKey | foreach { "{0}" -f $_.OA3xOriginalProductKey }
slmgr.vbs /ipk $key
Get Windows version:
Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion, OsHardwareAbstractionLayerVersion
Get Activation status:
Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } | select Description, LicenseStatus
0: Unlicensed
1: Licensed
2: Out-Of-Box Grace Period
3: Out-Of-Tolerance Grace Period
4: Non-Genuine Grace Period
5: Notification
6: Extended Grace
Get key:
wmic path SoftwareLicensingService get OA3xOriginalProductKey
Set Key:
slmgr.vbs /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX
or
changepk.exe /ProductKey W269N-WFGWX-YVC9B-4J6C9-T83GX
Activate:
slmgr.vbs /ato
Upgrade Home to Pro:
Changepk.exe /ProductKey VK7JG-NPHTM-C97JM-9MPGT-3V66T
Get key from registry:
$registryPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$digitalProductId = (Get-ItemProperty -Path $registryPath -Name DigitalProductId).DigitalProductId
$keyOffset = 52
$isWin8OrLater = [math]::Floor($digitalProductId[66] / 6) -band 1
$digitalProductId[66] = ($digitalProductId[66] -band 0xF7) -bor (($isWin8OrLater -band 2) * 4)
$chars = "BCDFGHJKMPQRTVWXY2346789"
$productKey = ""
for ($i = 24; $i -ge 0; $i--) {
$current = 0
for ($j = 14; $j -ge 0; $j--) {
$current = $current * 256
$current = $digitalProductId[$j + $keyOffset] + $current
$digitalProductId[$j + $keyOffset] = [math]::Floor($current / 24)
$current = $current % 24
}
$productKey = $chars[$current] + $productKey
}
if ($isWin8OrLater -eq 1) {
$keyPart1 = $productKey.Substring(1, $current)
$keyPart2 = $productKey.Substring($current + 1, $productKey.Length - $current - 1)
$productKey = $keyPart1 + "N" + $keyPart2
}
$formattedKey = ($productKey -split '(.{5})' | Where-Object { $_ }) -join '-'
Write-Host $formattedKey