PowerShell – Activate Windows

email me

This is the PowerShell code to activate Windows.

$computer = gc env:computername
$key = "aaaaa-bbbbb-ccccc-ddddd-eeeee"
$service = get-wmiObject -query "select * from SoftwareLicensingService" -computername $computer
$service.InstallProductKey($key)
$service.RefreshLicenseStatus()

 

Notes

https://gallery.technet.microsoft.com/scriptcenter/OS-Activation-by-MAK-using-e8a8ad2c

Command line method
slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
slmgr.vbs /ato

List available editions for upgrade
DISM /online /Get-TargetEditions

To upgrade from evaluation to standard
DISM /online /Set-Edition:ServerStandard /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX /AcceptEula