Activating Windows with PowerShell

You want to activate Windows using PowerShell?  Here you go:

$computer = gc env:computername

$key = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"

$service = get-wmiObject -query "select * from SoftwareLicensingService" -computername $computer

$service.InstallProductKey($key)

$service.RefreshLicenseStatus()

 

Note: $key will be followed by your legally obtained product key :)