Snippets

Marcelo Abeldaño activar 2K12 R2

Created by Marcelo Abeldaño
# 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=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.
     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"
     }

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.