Fixing Windows Activation in Intune

1 minute read

I’m currently working on a project where we’re migrating everything we can of client computers to Intune. The process has been to take in all the client computers, grab all the autopilot-info and reinstall them from SCCM with a blank Windows 11 ready for Out-of-box-experience. In this process we accidentally installed them with a KMS license key. Which is a problem, since we’re not going to use KMS for these clients. So we needed to change the license key to the correct one, and activate Windows.

I found a few different ways to do this, but the ones that seemed easy and elegant (like this one:, just didn’t work. Which isn’t that weird, because this is to install an upgrade key, which assumes that the computer is already activated. And since the computer thinks it’s supposed to access a KMS server, it isn’t.

So after a little bit of trial and error, I found something that works for us: It’s powershell scripts that we run in Intune, first a detection script:

# First get the active license object from the computer
$license = get-ciminstance softwarelicensingproduct | where-object {$_.PartialProductKey}
# check if the license object is a KMS license
if ($license.description -like "*KMS*") {
    # if it is a KMS license, exit with error code 1
 exit 1
} else {
    # if it is not a KMS license, exit with error code 0
 exit 0

And then a remediation script:

# Remove the active product key with slmgr (suppressed from output)
slmgr //b /upk
# Remove the name of the KMS server 
slmgr //b /ckms
# Add the new product key
slmgr //b /ipk <product key>

If you need to do this:

  • Go to Intune -> Devices -> Windows -> Scripts
  • Create new script
  • Give it a name and description Intune script
  • Add the detection script
  • Add the remediation script
  • Leave everything else as default
  • Choose the scope
  • Assign it to the computers you want to run it on
  • Save it

If you want to download the scripts, they can also be found in my github repo

That’s it.