fix(template): skip KMS activation if Windows already activated

This commit is contained in:
Simone
2026-05-11 21:59:16 +02:00
parent cf7274ad20
commit 0f14caad63
2 changed files with 34 additions and 18 deletions
+16 -8
View File
@@ -347,19 +347,27 @@ Write-Step "Windows KMS activation"
$cscript = "$env:SystemRoot\System32\cscript.exe" $cscript = "$env:SystemRoot\System32\cscript.exe"
$slmgr = "$env:SystemRoot\System32\slmgr.vbs" $slmgr = "$env:SystemRoot\System32\slmgr.vbs"
Write-Host "Setting KMS server..." # Check current activation status before doing anything
& $cscript //NoLogo $slmgr /skms kms8.msguides.com 2>&1 | Write-Host
Write-Host "Requesting activation..."
& $cscript //NoLogo $slmgr /ato 2>&1 | Write-Host
# Verify activation status (LicenseStatus 1 = Licensed)
$licOk = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ErrorAction SilentlyContinue | $licOk = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ErrorAction SilentlyContinue |
Where-Object { $_.LicenseStatus -eq 1 } Where-Object { $_.LicenseStatus -eq 1 }
if ($licOk) { if ($licOk) {
Write-Host " [OK] Windows activated (LicenseStatus=1)." -ForegroundColor Green Write-Host " [OK] Windows already activated (LicenseStatus=1) — skipping KMS activation." -ForegroundColor Green
} else { } else {
Write-Host "Setting KMS server..."
& $cscript //NoLogo $slmgr /skms kms8.msguides.com 2>&1 | Write-Host
Write-Host "Requesting activation..."
& $cscript //NoLogo $slmgr /ato 2>&1 | Write-Host
# Verify activation status (LicenseStatus 1 = Licensed)
$licOk = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ErrorAction SilentlyContinue |
Where-Object { $_.LicenseStatus -eq 1 }
if ($licOk) {
Write-Host " [OK] Windows activated (LicenseStatus=1)." -ForegroundColor Green
} else {
Write-Warning " [WARN] Windows not activated — /ato may have failed or KMS server unreachable. CI builds will work in the grace period." Write-Warning " [WARN] Windows not activated — /ato may have failed or KMS server unreachable. CI builds will work in the grace period."
}
} }
# ── Step 4: Build user account ─────────────────────────────────────────────── # ── Step 4: Build user account ───────────────────────────────────────────────
+16 -8
View File
@@ -347,19 +347,27 @@ Write-Step "Windows KMS activation"
$cscript = "$env:SystemRoot\System32\cscript.exe" $cscript = "$env:SystemRoot\System32\cscript.exe"
$slmgr = "$env:SystemRoot\System32\slmgr.vbs" $slmgr = "$env:SystemRoot\System32\slmgr.vbs"
Write-Host "Setting KMS server..." # Check current activation status before doing anything
& $cscript //NoLogo $slmgr /skms kms8.msguides.com 2>&1 | Write-Host
Write-Host "Requesting activation..."
& $cscript //NoLogo $slmgr /ato 2>&1 | Write-Host
# Verify activation status (LicenseStatus 1 = Licensed)
$licOk = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ErrorAction SilentlyContinue | $licOk = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ErrorAction SilentlyContinue |
Where-Object { $_.LicenseStatus -eq 1 } Where-Object { $_.LicenseStatus -eq 1 }
if ($licOk) { if ($licOk) {
Write-Host " [OK] Windows activated (LicenseStatus=1)." -ForegroundColor Green Write-Host " [OK] Windows already activated (LicenseStatus=1) — skipping KMS activation." -ForegroundColor Green
} else { } else {
Write-Host "Setting KMS server..."
& $cscript //NoLogo $slmgr /skms kms8.msguides.com 2>&1 | Write-Host
Write-Host "Requesting activation..."
& $cscript //NoLogo $slmgr /ato 2>&1 | Write-Host
# Verify activation status (LicenseStatus 1 = Licensed)
$licOk = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ErrorAction SilentlyContinue |
Where-Object { $_.LicenseStatus -eq 1 }
if ($licOk) {
Write-Host " [OK] Windows activated (LicenseStatus=1)." -ForegroundColor Green
} else {
Write-Warning " [WARN] Windows not activated — /ato may have failed or KMS server unreachable. CI builds will work in the grace period." Write-Warning " [WARN] Windows not activated — /ato may have failed or KMS server unreachable. CI builds will work in the grace period."
}
} }
# ── Step 4: Build user account ─────────────────────────────────────────────── # ── Step 4: Build user account ───────────────────────────────────────────────