Changing the product key of Windows from MAK to KMS with a PowerShell script

This article explains the basic steps to change the product key of an already installed Windows system with a PowerShell script. This becomes a matter of interest for example when you plan to deploy a Key Management Service (KMS) on your network. KMS activates Microsoft products on-premises without the need to go all the way over the public internet to Microsoft server.


The Volume Licensed editions of Windows all come with a KMS product key pre-installed. What this means is that when the system boots fresh up, it will search a local KMS server and activate itself automatically. All this happens in the background and is invisible to the desktop user. Another option is to use MAK (Multiple Activation) product keys, which all activate independently using Microsoft servers.

Suppose you’ve installed a 100 computers with a carefully placed MAK key with an automated installation procedure (like SCCM or WDS). Now you decide it’s time to put an end to the traffic that goes out to Microsoft during these activations. The systems are already activated and fully operational. Some might ask, why go through the trouble touching those? You could just change the installation procedure to get rid of the MAK key in new installations and let the rest be. Well, I like my systems similarly managed and installed.

OK, you now want to change the product key of the already 100 computers from MAK to KMS, read on.

Changing the Product Key

Activation in Windows is handled with the good old slmgr.vbs Visual Basic script located in %WINDIR%\system32\. The most useful parameters are:

  • /dli and /dlv – display licensing information
  • /ipk <product_key> – install product key
  • /ato – activate Windows

Given that, to change the product key on MAK activated machines you would run the following lines in an elevated command promt.

cscript.exe slmgr.vbs /ipk <KMS_KEY>
cscript.exe slmgr.vbs /ato

The first line installs the KMS product key and the seconds goes on and activates the system against a local KMS server. The KMS_KEY here is the client key! Don’t use your KMS server key, you use it to activate the KMS server with Microsoft. The current list of the KMS client setup keys can be found here.

Next step would be wrapping these two lines into a single script and deploying it with Group Policy (GPO) to be run from a computer startup script or any other way that you find suitable. The script can be either a vbscript or a PowerShell script. To invoke the cscript lines, you can use the Invoke-Expression cmdlet.

The only thing wrong with this is that you don’t want to run this more than once.

Determining current product type

To determine the current product key from a running Windows involves some WMI digging. The SoftwareLicensingProduct class, in particular, is the one you need. To get to that you can run the following lines. Notice the back tick mark to mark a line break.

$cimsession = New-CimSession
$pk_type = get-ciminstance -class SoftwareLicensingProduct `
-CimSession $cimsession|where {$ -match 'windows' `
-AND $_.licensefamily}|where LicenseStatus -ne 0

The first line gets and stores a CimSession and the second gets a SoftwareLicensingProduct whose LicenseStatus is something other than 0.

Then you just check whether the key used includes the string MAK. Additionally, if you have many OS versions in production you can check that too.

if ( $pk_type.Description.Contains("MAK") -and `
$pk_type.Description.Contains("Windows(R) 7"))

…then if those two conditions are true, go on and do the slmgr.vbs magic.

The script

To sum it all up, here’s the complete script.

# Strict-Mode - remember this, it's important!
Set-StrictMode -Version Latest

# variables
$cimsession = New-CimSession
$pk_type = get-ciminstance -class SoftwareLicensingProduct `
-CimSession $cimsession|where {$ -match 'windows' -AND `
$_.licensefamily}|where LicenseStatus -ne 0

if ( $pk_type.Description.Contains("MAK") -and `
$pk_type.Description.Contains("Windows(R) 7")) {
  # We have a MAK key and Windows 7, let's change the product
  # key and activate
  Invoke-Expression "cscript //t:20 c:\windows\system32\slmgr.vbs `
    /ipk <KMS_KEY>"
  Invoke-Expression "cscript //t:20 c:\windows\system32\slmgr.vbs `

The //t:20 is a timeout value of twenty seconds in case something goes wrong.

There must be plenty of other possible solutions to this, but this one worked for me.

For more information on Volume Activation go to TechNet.

12 thoughts on “Changing the product key of Windows from MAK to KMS with a PowerShell script

  1. I’ve been surfing online more than three hours these days, but I by no means found any attention-grabbing article like yours. It’s lovely worth sufficient for me. In my view, if all webmasters and bloggers made excellent content material as you did, the net shall be much more helpful than ever before.

  2. Pingback: Google

  3. thanks for trying the sicprt!I think the cause of why the sicprt doesnt work is because part of wmi contents is translated to french.My first guess would be Hosting Computer System is translated to French.If you run the following cmdline on a hyper V host:wmic /namespace:\\root\virtualization PATH Msvm_ComputerSystem GET CaptionIt should show Caption on the first line. On the second line, the french equivalent to Hosting Computer System and the rest french words for virtual machine If you replace Hosting Computer System and virtual machine in the sicprt with the french equivalents. It should work. unless they decided to translate alot more.Please share the outcome!

Leave a Reply

Your email address will not be published. Required fields are marked *

Please, do the math and help fight spam * Time limit is exhausted. Please reload the CAPTCHA.