# Self-elevate the script if required# Thanks to Jeff Guillet at http://www.expta.com/2017/03/how-to-self-elevate-powershell-script.htmlif(-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.UnboundArgumentsStart-Process-FilePathPowerShell.exe-VerbRunas-ArgumentList$CommandLineExit}} # Run your code that needs to be elevated herefunctionShow-Menu{param([string]$Title = 'Windows Evaluation Activation')clsWrite-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:$ProductKeybreak} '2' {Dism/online/Set-Edition:ServerDatacenter/AcceptEula/ProductKey:$ProductKeybreak} }Write-Host"Activation Finished"}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.