This may work for other later Operating Systems but it has been tested on 2012 R2.
I installed 2012 R2 on a brand new server as a trial and then later the license arrived, while trying to install the license, it was failed with error saying “that key is not valid for this version of Windows”.
Firstly, check to make sure of what version you are using by running the following command
dism /online /get-currentedition
and check the possible target edition
dism /online /get-targeteditions
and if yours is supported then all you need is the new key and run the following command, be sure you are connected to the internet.
dism /online /set-edition:EDITION /product xxxxx-xxxxx-xxxxx-xxxxx-xxxxx /accepteula
if you don’t put /accepteula it will not work.
Also, Server 2012 won’t allow you to change the product, to do so , do the following
Server 2012’s system properties do not allow you to change the Product key.
To change this you need to open power shell in privileged mode and enter the following cmd’s.
slmgr -upk (this removes the current Product Key)
slmgr -ipk XXXX-XXXX-XXXX-XXXX (this installs the new Product Key)
Please see Microsoft’s Article ID: 2750773: