# 1. Restore default schemes to ensure all standard subgroups exist, then switch to Balanced powercfg /restoredefaultschemes powercfg /setactive SCHEME_BALANCED # 2. GUID Definitions $BUTTONS_SUBGROUP = "4f971e89-eebd-4455-a8de-9e59040e7347" $POWER_BUTTON = "7648efa3-dd9c-4e3e-b566-50f929386280" $SLEEP_BUTTON = "96996bc0-ad50-47ec-923b-6f41874dd9e6" $VIDEO_SUBGROUP = "7516b95f-f776-4464-8c53-06167f40cc99" $SCREEN_TIMEOUT = "3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e" $SLEEP_SUBGROUP = "238c9fa8-0aad-41ed-83f4-97be242c8f20" $SUSPEND_TIMEOUT = "29f6c1db-86da-48c5-9fdb-f2b67b1f44da" $HIBERNATE_TIMEOUT = "9d7815a6-7ee4-497e-8888-515a05f02364" $ENERGY_SUBGROUP = "de830923-a562-41af-a086-e3a2c6bad2da" $ENERGY_POLICY = "5c5bb349-ad29-4ee2-9d0b-2b25270f7a81" $BATTERY_THRESHOLD = "e69653ca-cf7f-4f05-aa73-cb833fa90ad4" # 3. Helper: apply a powercfg setting and validate via registry function Set-PowerSetting { param([string]$Sub, [string]$Setting, [int]$AC, [int]$DC) # Always attempt — no pre-check, powercfg will simply not write if unsupported powercfg /setacvalueindex SCHEME_CURRENT $Sub $Setting $AC 2>&1 | Out-Null powercfg /setdcvalueindex SCHEME_CURRENT $Sub $Setting $DC 2>&1 | Out-Null # If powercfg wrote it, the registry key will exist — use that as the ground truth $schemeGuid = (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes" -EA SilentlyContinue).ActivePowerScheme $regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\$schemeGuid\$Sub\$Setting" if (-not (Test-Path $regPath)) { return "N/A" } $props = Get-ItemProperty $regPath -EA SilentlyContinue $acGot = $props.ACSettingIndex $dcGot = $props.DCSettingIndex if ($acGot -eq $AC -and $dcGot -eq $DC) { return "PASS" } return "FAIL (AC=$acGot DC=$dcGot, expected $AC/$DC)" } # 4. Apply all powercfg settings $pcfg = [ordered]@{} $pcfg["Power Button → Shut Down"] = Set-PowerSetting $BUTTONS_SUBGROUP $POWER_BUTTON 3 3 $pcfg["Sleep Button → Shut Down"] = Set-PowerSetting $BUTTONS_SUBGROUP $SLEEP_BUTTON 3 3 $pcfg["Screen Timeout → 10 min"] = Set-PowerSetting $VIDEO_SUBGROUP $SCREEN_TIMEOUT 600 600 $pcfg["Sleep → Never"] = Set-PowerSetting $SLEEP_SUBGROUP $SUSPEND_TIMEOUT 0 0 $pcfg["Hibernate → Never"] = Set-PowerSetting $SLEEP_SUBGROUP $HIBERNATE_TIMEOUT 0 0 $pcfg["Energy Saver Policy → Off"] = Set-PowerSetting $ENERGY_SUBGROUP $ENERGY_POLICY 0 0 $pcfg["Energy Saver Threshold → 0%"] = Set-PowerSetting $ENERGY_SUBGROUP $BATTERY_THRESHOLD 0 0 # 5. Windows Update registry settings $WUPath = "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" if (-not (Test-Path $WUPath)) { New-Item -Path $WUPath -Force | Out-Null } Set-ItemProperty -Path $WUPath -Name "AllowAutoWindowsUpdateDownloadOverMeteredNetwork" -Value 1 -Type DWord -Force Set-ItemProperty -Path $WUPath -Name "RestartNotificationsAllowed2" -Value 1 -Type DWord -Force Set-ItemProperty -Path $WUPath -Name "SmartActiveHoursState" -Value 0 -Type DWord -Force Set-ItemProperty -Path $WUPath -Name "ActiveHoursStart" -Value 5 -Type DWord -Force Set-ItemProperty -Path $WUPath -Name "ActiveHoursEnd" -Value 23 -Type DWord -Force # MS Update — skip COM call if already registered (E_ACCESSDENIED = already present) $MUKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\7971f918-a847-4430-9279-4a52d1efe18d" $muOk = Test-Path $MUKey if (-not $muOk) { try { $svcMgr = New-Object -ComObject Microsoft.Update.ServiceManager $svcMgr.AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") | Out-Null $muOk = $true } catch { Write-Warning "MS Update registration failed: $_" } } # 6. Flush active scheme then set Best Performance overlay via powercfg powercfg /setactive SCHEME_CURRENT $null = powercfg /overlaysetactive ded574b5-45a0-4f42-8737-46345c09c238 2>&1 # 7. Verify registry values $reg = [ordered]@{} $overlayVal = (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes" -EA SilentlyContinue).ActiveOverlayAcPowerScheme $reg["Power Mode → Best Performance"] = $overlayVal -eq "ded574b5-45a0-4f42-8737-46345c09c238" $reg["WU Metered Downloads → On"] = (Get-ItemProperty $WUPath "AllowAutoWindowsUpdateDownloadOverMeteredNetwork" -EA SilentlyContinue).AllowAutoWindowsUpdateDownloadOverMeteredNetwork -eq 1 $reg["WU Restart Notification → On"] = (Get-ItemProperty $WUPath "RestartNotificationsAllowed2" -EA SilentlyContinue).RestartNotificationsAllowed2 -eq 1 $reg["WU Active Hours → Manual"] = (Get-ItemProperty $WUPath "SmartActiveHoursState" -EA SilentlyContinue).SmartActiveHoursState -eq 0 $reg["WU Active Hours → 5AM-11PM"] = ((Get-ItemProperty $WUPath "ActiveHoursStart" -EA SilentlyContinue).ActiveHoursStart -eq 5) -and ((Get-ItemProperty $WUPath "ActiveHoursEnd" -EA SilentlyContinue).ActiveHoursEnd -eq 23) $reg["WU Other MS Products → On"] = $muOk # 8. Build popup $lines = @("--- Power Settings (powercfg) ---") foreach ($k in $pcfg.Keys) { $v = $pcfg[$k] $pfx = if ($v -eq "PASS") { "[PASS]" } elseif ($v -eq "N/A") { "[ N/A]" } else { "[FAIL]" } $detail = if ($v -notin "PASS","N/A") { " → $v" } else { "" } $lines += "$pfx $k$detail" } $lines += "" $lines += "--- Registry Verification ---" foreach ($k in $reg.Keys) { $lines += "$(if ($reg[$k]) { '[PASS]' } else { '[FAIL]' }) $k" } Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.MessageBox]::Show( "Uniform Stores IT Deployment`n`n" + ($lines -join "`n"), "Uniform Stores IT Deployment", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information ) | Out-Null