Skip to content

Commit

Permalink
Moving initial activation out of loop (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkatyl authored Dec 11, 2024
1 parent 277e483 commit 584c3ea
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sysprep/activate_instance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function Activate-Instance {
#>

[string]$license_key = $null
[int]$retry_count = 3 # Try activation three times.
[int]$retry_count = 2 # Retry activation two additional times.

$license_key = Get-ProductKmsClientKey
if (-not $license_key) {
Expand All @@ -115,9 +115,10 @@ function Activate-Instance {
# Apply the license key to the host.
& cscript //nologo $env:windir\system32\slmgr.vbs /ipk $license_key

Write-Output 'Activating instance...'
& cscript //nologo $env:windir\system32\slmgr.vbs /ato

while ($retry_count -gt 0) {
Write-Output 'Activating instance...'
& cscript //nologo $env:windir\system32\slmgr.vbs /ato
# Helps to avoid activation failures.
Start-Sleep -Seconds 1

Expand All @@ -132,6 +133,7 @@ function Activate-Instance {
}
else {
Write-Output "Activation failed. Will try $retry_count more time(s)."
& cscript //nologo $env:windir\system32\slmgr.vbs /ato
}
}
}
Expand Down

0 comments on commit 584c3ea

Please sign in to comment.