Windows Activation and Edition Change
I work for an Oil Services company, and while most of our computers are Domain Joined and connected to our Corporate Network, we have several computers that are Remote and in Workgroups. These computers can't readily talk to our KMS to stay Activated as they are Offline for extended periods of time
The need to create a Scheduled Task to sit on a computer for Activating Windows using a MAK (Multiple Activation Key) is necessary.

Activation Script

Below is a quick PowerShell script to activate Windows 10 Enterprise using a MAK. Simply replace the $MakKey with your own
1
$TaskName = 'Activate MAK Windows 10 Enterprise'
2
$MakKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
3
#======================================================================================
4
# Logs
5
#======================================================================================
6
$TaskLogs = "$env:SystemRoot\Logs\Activation"
7
if (!(Test-Path $TaskLogs)) {New-Item $TaskLogs -ItemType Directory -Force | Out-Null}
8
$TaskLogName = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$TaskName.log"
9
Start-Transcript -Path (Join-Path $TaskLogs $TaskLogName)
10
#======================================================================================
11
# Operating System
12
#======================================================================================
13
$OSCaption = $((Get-WmiObject -Class Win32_OperatingSystem).Caption).Trim()
14
$OSArchitecture = $((Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture).Trim()
15
$OSVersion = $((Get-WmiObject -Class Win32_OperatingSystem).Version).Trim()
16
$OSBuildNumber = $((Get-WmiObject -Class Win32_OperatingSystem).BuildNumber).Trim()
17
#======================================================================================
18
# Variables
19
#======================================================================================
20
Write-Host "OSCaption: $OSCaption" -ForegroundColor Cyan
21
Write-Host "OSArchitecture: $OSArchitecture" -ForegroundColor Cyan
22
Write-Host "OSVersion: $OSVersion" -ForegroundColor Cyan
23
Write-Host "OSBuildNumber: $OSBuildNumber" -ForegroundColor Cyan
24
#======================================================================================
25
# Set SLMGR
26
#======================================================================================
27
if (Test-Path "$env:windir\SYSWOW64\slmgr.vbs") {
28
$slmgr = "$env:windir\SYSWOW64\slmgr.vbs"
29
} else {
30
$slmgr = "$env:windir\System32\slmgr.vbs"
31
}
32
#======================================================================================
33
# OS Activation
34
#======================================================================================
35
if (Test-Path $slmgr) {
36
Write-Host "**********************"
37
Write-Host "Display Licensing Information"
38
Write-Host "Command Line: cscript //nologo $slmgr /dlv"
39
cscript //nologo $slmgr /dlv
40
Write-Host "**********************"
41
Write-Host "Install Product Key"
42
Write-Host "Command Line: cscript //nologo $slmgr /ipk $MakKey"
43
cscript //nologo $slmgr /ipk $MakKey
44
Write-Host "**********************"
45
Write-Host "Activate Windows"
46
Write-Host "Command Line: cscript //nologo $slmgr /ato"
47
cscript //nologo $slmgr /ato
48
Write-Host "**********************"
49
Write-Host "Display Licensing Information"
50
Write-Host "Command Line: cscript //nologo $slmgr /dlv"
51
cscript //nologo $slmgr /dlv
52
Write-Host "**********************"
53
Write-Host "Display Installation ID for Offline Activation"
54
Write-Host "Command Line: cscript //nologo $slmgr /dti"
55
cscript //nologo $slmgr /dti
56
}
57
Write-Host "**********************"
58
Write-Warning "Internet access may be required to complete activation"
59
#======================================================================================
60
# Complete
61
#======================================================================================
62
Stop-Transcript
Copied!

Inception

You are going to have to take this script, and put in in your Task Builder script to create the Task so it can be Encoded
1
#======================================================================================
2
# Run as Administrator Elevated
3
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
4
Write-Verbose "Checking User Account Control settings" -Verbose
5
if ((Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System).EnableLUA -eq 0) {
6
#UAC Disabled
7
Write-Verbose "User Account Control is Disabled" -Verbose
8
Write-Verbose "You will need to correct your UAC Settings before running this script" -Verbose
9
Write-Verbose "Try running this script in an Elevated PowerShell session ... Exiting" -Verbose
10
Start-Sleep -s 10
11
Exit 0
12
} else {
13
#UAC Enabled
14
Write-Verbose "UAC is Enabled. Relaunching script with Elevated Permissions" -Verbose
15
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs -Wait
16
Exit 0
17
}
18
} else {
19
Write-Verbose "Running with Elevated Permissions" -Verbose
20
}
21
#======================================================================================
22
# Task Properties
23
$TaskName = 'Activate MAK Windows 10 Enterprise'
24
$TaskPath = '\Corporate\Activation'
25
$Description = @"
26
Upgrades Edition to Windows 10 Enterprise
27
Activates Windows using Multiple Activation Key
28
Internet access may be required to complete the Activation Process
29
Transcripts are stored in $env:SystemRoot\Logs\Activation
30
Runs as SYSTEM and does not display any progress or results
31
PowerShell Encoded Script
32
Version 21.1.19
33
"@
34
#======================================================================================
35
# Script
36
$TaskScript = @'
37
$TaskName = 'Activate MAK Windows 10 Enterprise'
38
$MakKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
39
#======================================================================================
40
# Logs
41
#======================================================================================
42
$TaskLogs = "$env:SystemRoot\Logs\Activation"
43
if (!(Test-Path $TaskLogs)) {New-Item $TaskLogs -ItemType Directory -Force | Out-Null}
44
$TaskLogName = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$TaskName.log"
45
Start-Transcript -Path (Join-Path $TaskLogs $TaskLogName)
46
#======================================================================================
47
# Operating System
48
#======================================================================================
49
$OSCaption = $((Get-WmiObject -Class Win32_OperatingSystem).Caption).Trim()
50
$OSArchitecture = $((Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture).Trim()
51
$OSVersion = $((Get-WmiObject -Class Win32_OperatingSystem).Version).Trim()
52
$OSBuildNumber = $((Get-WmiObject -Class Win32_OperatingSystem).BuildNumber).Trim()
53
#======================================================================================
54
# Variables
55
#======================================================================================
56
Write-Host "OSCaption: $OSCaption" -ForegroundColor Cyan
57
Write-Host "OSArchitecture: $OSArchitecture" -ForegroundColor Cyan
58
Write-Host "OSVersion: $OSVersion" -ForegroundColor Cyan
59
Write-Host "OSBuildNumber: $OSBuildNumber" -ForegroundColor Cyan
60
#======================================================================================
61
# Set SLMGR
62
#======================================================================================
63
if (Test-Path "$env:windir\SYSWOW64\slmgr.vbs") {
64
$slmgr = "$env:windir\SYSWOW64\slmgr.vbs"
65
} else {
66
$slmgr = "$env:windir\System32\slmgr.vbs"
67
}
68
#======================================================================================
69
# OS Activation
70
#======================================================================================
71
if (Test-Path $slmgr) {
72
Write-Host "**********************"
73
Write-Host "Display Licensing Information"
74
Write-Host "Command Line: cscript //nologo $slmgr /dlv"
75
cscript //nologo $slmgr /dlv
76
Write-Host "**********************"
77
Write-Host "Install Product Key"
78
Write-Host "Command Line: cscript //nologo $slmgr /ipk $MakKey"
79
cscript //nologo $slmgr /ipk $MakKey
80
Write-Host "**********************"
81
Write-Host "Activate Windows"
82
Write-Host "Command Line: cscript //nologo $slmgr /ato"
83
cscript //nologo $slmgr /ato
84
Write-Host "**********************"
85
Write-Host "Display Licensing Information"
86
Write-Host "Command Line: cscript //nologo $slmgr /dlv"
87
cscript //nologo $slmgr /dlv
88
Write-Host "**********************"
89
Write-Host "Display Installation ID for Offline Activation"
90
Write-Host "Command Line: cscript //nologo $slmgr /dti"
91
cscript //nologo $slmgr /dti
92
}
93
Write-Host "**********************"
94
Write-Warning "Internet access may be required to complete activation"
95
#======================================================================================
96
# Complete
97
#======================================================================================
98
Stop-Transcript
99
'@
100
#======================================================================================
101
# Encode the Script
102
$EncodedCommand = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($TaskScript))
103
#======================================================================================
104
# Splat the Task
105
$Action = @{
106
Execute = 'powershell.exe'
107
Argument = "-ExecutionPolicy ByPass -EncodedCommand $EncodedCommand"
108
}
109
$Principal = @{
110
UserId = 'SYSTEM'
111
RunLevel = 'Highest'
112
}
113
$Settings = @{
114
AllowStartIfOnBatteries = $true
115
Compatibility = 'Win8'
116
MultipleInstances = 'Parallel'
117
ExecutionTimeLimit = (New-TimeSpan -Minutes 60)
118
}
119
$ScheduledTask = @{
120
Action = New-ScheduledTaskAction @Action
121
Principal = New-ScheduledTaskPrincipal @Principal
122
Settings = New-ScheduledTaskSettingsSet @Settings
123
Description = $Description
124
}
125
#======================================================================================
126
# Build the Task
127
New-ScheduledTask @ScheduledTask | Register-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Force
128
#======================================================================================
129
# Apply Authenticated User Permissions
130
$Scheduler = New-Object -ComObject "Schedule.Service"
131
$Scheduler.Connect()
132
$GetTask = $Scheduler.GetFolder($TaskPath).GetTask($TaskName)
133
$GetSecurityDescriptor = $GetTask.GetSecurityDescriptor(0xF)
134
if ($GetSecurityDescriptor -notmatch 'A;;0x1200a9;;;AU') {
135
$GetSecurityDescriptor = $GetSecurityDescriptor + '(A;;GRGX;;;AU)'
136
$GetTask.SetSecurityDescriptor($GetSecurityDescriptor, 0)
137
}
Copied!

Create the Task

Simply execute the script to create the Scheduled Task. In my example, I have created one for Enterprise and Pro as I work with both editions in my environment. Each Edition should have a separate, unique MAK Key

Standard User Testing

So now I'm on the Internet completely disconnected from my Corporate Network and I need to Activate Windows using the MAK, so time to Change Product Key in Windows Settings
Unfortunately I am not an Admin of the computer, so no can do
Time to run the Scheduled Task and wait for it to complete running. Another check into Windows Activation and I am golden.
I'm able to alternate both of my Tasks and switch between Enterprise and Pro
The logging is a plus and very helpful if there are any issues that come up

GitHub

Here's a link to both scripts. Just add your MAK Keys and enjoy
ScheduledTasks/Corporate/Activation at main · OSDeploy/ScheduledTasks
GitHub
Last modified 8mo ago