Activating Windows Server 2012/2016 Evaluation Edition – My little script | Phy2Vir

An IT Blog covering anything from Physical to Virtual in I.T

Activating Windows Server 2012/2016 Evaluation Edition – My little script

When installing Windows Server Evaluation Edition 2012/2016 you cannot activate it using the normal process of clicking on change product key in the System Properties window.

When you try, you will receive an error which is different when using an OEM or Retail Key as shown below.

OEM Key – The product key you entered didn’t work. Check the product key and try again, or enter a different one. Error Code: 0xc004050

Retail Key – This edition cannot be upgraded

 

In order to active this edition of windows you need to use DISM Windows Edition-Servicing Command-Line Options.

Using the option /Get-TargetEditions will allow you to see the editions that the windows installation can be activated to. The below is the output after executing

DISM /Online /Get-TargetEditions

The result shows that the installation can be activated to ServerStandard or ServerDatacenter editions.

To activate this installation to Windows Server Standard Edition you would need to run the below command

Dism /online /Set-Edition:ServerStandard /AcceptEula /ProductKey:12345-12345-12345-12345-12345

For Datacenter Edition you need to run the command:

Dism /online /Set-Edition:ServerDatacenter /AcceptEula /ProductKey:12345-12345-12345-12345-12345

This is very simple and there isn’t much you can change about that.

I wanted to create a generic script which would allow me to execute it and give me the choice to activate the edition I need using an OEM or Retail Key. This can also be customised to do a specific edition and predefine a product key.

The script below also checks if the script is executed in an elevated Powershell window and if not it will open an elevated window and run the script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Self-elevate the script if required
# Thanks to Jeff Guillet at http://www.expta.com/2017/03/how-to-self-elevate-powershell-script.html
 
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
 if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
  $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
  Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
  Exit
 }
} 
# Run your code that needs to be elevated here
 
function Show-Menu
{
     param (
           [string]$Title = 'Windows Evaluation Activation'
     )
     cls
     Write-Host "================ $Title ================"
 
     Write-Host "1: Press '1' for Standard."
     Write-Host "2: Press '2' for Datacenter"
     Write-Host "3: Press 'q' or 'Q' to exit"
 
 }
 
     Show-Menu
     #Select the Edition you want to Activate.
     $input = Read-Host "Please make a selection"
     if (($input -ne "q") -or ($input-ne "Q"))
     {    
     #$ProductKey can be hard coded eg $ProductKey=12345-12345-12345-12345-12345
     $ProductKey = Read-Host "Enter Product Key"
     #The code to Active windows is executed depending on the version selected
     #This may take a long time. If it exceeds 2 hrs, Restart the server and try again.
     switch ($input)
     {
           '1' {
                Dism /online /Set-Edition:ServerStandard /AcceptEula /ProductKey:$ProductKey
                break
         } '2' {
               Dism /online /Set-Edition:ServerDatacenter /AcceptEula /ProductKey:$ProductKey
               break
               } 
     }
     Write-Host "Activation Finished"
     }

The below is the output of the script

This was run by right clicking the ps1 file and clicking on Run with Powershell. You will notice that the window is running in an elevated mode.

Please note that the operation may take a long time to process when it reaches 10%. this is very normal. On some systems it takes 5-10 minutes and on others it took longer. I even left the process running overnight and it would not complete. In that case terminate it and restart the OS and try again. This is not caused by the script.

So that is it. Hope someone may find it useful. I certainly did and enjoying putting it together 🙂

 


Post a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Advertisement

    hostifi.net
  • Advertisement

    Advertisements
  • Connect with me

  • Site Menu

  • Follow me on Twitter