fix(template): skip KMS activation if Windows already activated
This commit is contained in:
@@ -347,19 +347,27 @@ Write-Step "Windows KMS activation"
|
||||
$cscript = "$env:SystemRoot\System32\cscript.exe"
|
||||
$slmgr = "$env:SystemRoot\System32\slmgr.vbs"
|
||||
|
||||
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)
|
||||
# Check current activation status before doing anything
|
||||
$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
|
||||
Write-Host " [OK] Windows already activated (LicenseStatus=1) — skipping KMS activation." -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-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."
|
||||
}
|
||||
}
|
||||
|
||||
# ── Step 4: Build user account ───────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user