Using device product key to activate Windows

During a recent project, we encountered issues with Windows 11 not being activated on newly purchased and deployed devices. This was quite surprising, given that the devices were bought with a valid Windows 11 licence.

After some digging, we notice that the licence key currently being used ended with –T83GX and after running that through Google we ended on the following Page: Key Management Services (KMS) client activation and product keys for Windows Server and Windows | Microsoft Learn

So it seems that because we used a plain Win 11 Image to install the devices before running them through the Autopilot-Deployment Windows used the KMS Key from the Image and was not able to activate as of that. So we dug a bit deeper, and we’re able to fetch the Original Product Key from the device using the following command:

PowerShell
(Get-WmiObject -Class SoftwareLicensingService).OA3xOriginalProductKey

And with the following command, we were able to set it as the currently active key. In the Script we add the //b Parameter to prevent the popup that may block the script during automated deployment.

BAT (Batchfile)
slmgr /ipk productKey

Tested on a few devices and Windows was running smoothly, but we’re not fans of the good old «Sneaker-IT» and having to run those commands manually on every device. So we created a little script to fetch the Original Key and use it for activation. We can use some regex to validate our product key. This lead us to the following script, which we were able to deploy to all devices and enjoy the rest of the day (or maybe debug the next issues).

PowerShell
try {
    Write-Host "extracting key"
    $KeyResult = (Get-WmiObject -Class SoftwareLicensingService).OA3xOriginalProductKey
    
    # print the result
    Write-Host "found key: $KeyResult"

    # Use regex to match the product key format (5 blocks of alphanumeric characters)
    $regex = '[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}'
    
    # Extract the product key
    $productKey = [regex]::matches($KeyResult, $regex).Value
    
    if ($null -eq $productKey) {
        Write-Host "found key is not valid"
        exit 1
    }
    
    # register with device key
    Start-Process "slmgr" -ArgumentList "/ipk $($productKey) //b" -Wait 
} catch {
    Write-Host "unable to set product key: $($_.Exception.Message)"
    exit 1
}

exit 0

Finally, we could deploy above scripts to the clients using Intune and enjoy a smooth rollout of the new devices.

Kommentare

Schreiben Sie einen Kommentar

Ihre E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert