diff --git a/template/Setup-WinBuild2022.ps1 b/template/Setup-WinBuild2022.ps1 index 089b457..165a2c1 100644 --- a/template/Setup-WinBuild2022.ps1 +++ b/template/Setup-WinBuild2022.ps1 @@ -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 ─────────────────────────────────────────────── diff --git a/template/Setup-WinBuild2025.ps1 b/template/Setup-WinBuild2025.ps1 index fee4dbe..e34ed11 100644 --- a/template/Setup-WinBuild2025.ps1 +++ b/template/Setup-WinBuild2025.ps1 @@ -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 ───────────────────────────────────────────────