+# 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
+# Run your code that needs to be elevated here
+ [string]$Title = 'Windows Evaluation Activation'
+ 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"
+ #Select the Edition you want to Activate.
+ $input = Read-Host "Please make a selection"
+ if (($input -ne "q") -or ($input-ne "Q"))
+ $ProductKey=DBGBW-NPF86-BJVTX-K3WKJ-MTB6V
+ #$ProductKey=DBGBW-NPF86-BJVTX-K3WKJ-MTB6V
+ #$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.
+ Dism /online /Set-Edition:ServerStandard /AcceptEula /ProductKey:$ProductKey
+ Dism /online /Set-Edition:ServerDatacenter /AcceptEula /ProductKey:$ProductKey
+ Write-Host "Activation Finished"