|
1 | 1 | <#PSScriptInfo |
2 | | -.VERSION 2.9 |
| 2 | +.VERSION 2.10 |
3 | 3 | .GUID 8f7c3b2a-1d4e-5f6a-9b8c-0d1e2f3a4b5c |
4 | 4 | .AUTHOR bivlked |
5 | 5 | .COMPANYNAME |
|
12 | 12 | .REQUIREDSCRIPTS |
13 | 13 | .EXTERNALSCRIPTDEPENDENCIES |
14 | 14 | .RELEASENOTES |
| 15 | + v2.10: Added auto-update check at startup (checks PSGallery for new version) |
15 | 16 | v2.9: Fixed PSWindowsUpdate installation hanging (TLS 1.2, timeouts) |
16 | 17 | v2.8: Fixed Disk Cleanup timeout issues |
17 | 18 | v2.7: UI improvements for final statistics |
|
20 | 21 |
|
21 | 22 | <# |
22 | 23 | .SYNOPSIS |
23 | | - WinClean - Ultimate Windows 11 Maintenance Script v2.9 |
| 24 | + WinClean - Ultimate Windows 11 Maintenance Script v2.10 |
24 | 25 | .DESCRIPTION |
25 | 26 | Комплексный скрипт для обновления и очистки Windows 11: |
26 | 27 | - Обновление Windows (включая драйверы) |
|
34 | 35 | - Подробный цветной вывод + лог-файл |
35 | 36 | .NOTES |
36 | 37 | Author: biv |
37 | | - Version: 2.9 |
| 38 | + Version: 2.10 |
38 | 39 | Requires: PowerShell 7.1+, Windows 11, Administrator rights |
| 40 | + Changes in 2.10: |
| 41 | + - Added auto-update check: script checks PSGallery for newer version at startup |
| 42 | + - Added Test-ScriptUpdate function: compares local version with PSGallery |
| 43 | + - Added Invoke-ScriptUpdate function: prompts user and performs update if confirmed |
| 44 | + - Update check runs after reboot check, before main operations |
| 45 | + - Shows manual update instructions if script was downloaded manually (not via PSGallery) |
| 46 | + - Respects ReportOnly mode and non-interactive environments |
39 | 47 | Changes in 2.9: |
40 | 48 | - Fixed PSWindowsUpdate installation hanging: added TLS 1.2 enforcement |
41 | 49 | - Added Test-PSGalleryConnection function: pre-checks PowerShell Gallery availability |
@@ -196,6 +204,9 @@ if (-not $LogPath) { |
196 | 204 | $script:LogPath = $LogPath |
197 | 205 | } |
198 | 206 |
|
| 207 | +# Script version (single source of truth for version checking) |
| 208 | +$script:Version = "2.10" |
| 209 | + |
199 | 210 | # Protected paths that should never be deleted |
200 | 211 | $script:ProtectedPaths = @( |
201 | 212 | $env:SystemRoot, |
@@ -418,6 +429,135 @@ function Test-PSGalleryConnection { |
418 | 429 | } |
419 | 430 | } |
420 | 431 |
|
| 432 | +function Test-ScriptUpdate { |
| 433 | + <# |
| 434 | + .SYNOPSIS |
| 435 | + Проверяет наличие обновлений WinClean в PowerShell Gallery |
| 436 | + .DESCRIPTION |
| 437 | + Сравнивает текущую версию скрипта с последней версией в PowerShell Gallery. |
| 438 | + Проверяет, был ли скрипт установлен через PSGallery (для возможности автообновления). |
| 439 | + .OUTPUTS |
| 440 | + [hashtable] с информацией об обновлении или $null если обновление не требуется |
| 441 | + #> |
| 442 | + # Check if we can reach PSGallery |
| 443 | + if (-not (Test-PSGalleryConnection)) { |
| 444 | + return $null |
| 445 | + } |
| 446 | + |
| 447 | + try { |
| 448 | + $currentVersion = [Version]$script:Version |
| 449 | + |
| 450 | + # Query PSGallery for latest version |
| 451 | + $galleryScript = Find-Script -Name "WinClean" -Repository PSGallery -ErrorAction Stop |
| 452 | + $latestVersion = [Version]$galleryScript.Version |
| 453 | + |
| 454 | + if ($latestVersion -gt $currentVersion) { |
| 455 | + # Check if installed via PSGallery (for auto-update capability) |
| 456 | + $installedScript = Get-InstalledScript -Name "WinClean" -ErrorAction SilentlyContinue |
| 457 | + |
| 458 | + return @{ |
| 459 | + CurrentVersion = $currentVersion.ToString() |
| 460 | + LatestVersion = $latestVersion.ToString() |
| 461 | + IsInstalled = $null -ne $installedScript |
| 462 | + ReleaseNotes = $galleryScript.ReleaseNotes |
| 463 | + } |
| 464 | + } |
| 465 | + } catch { |
| 466 | + # Silently fail - update check is not critical |
| 467 | + Write-Log "Update check failed: $_" -Level WARNING |
| 468 | + } |
| 469 | + |
| 470 | + return $null |
| 471 | +} |
| 472 | + |
| 473 | +function Invoke-ScriptUpdate { |
| 474 | + <# |
| 475 | + .SYNOPSIS |
| 476 | + Предлагает пользователю обновить WinClean и выполняет обновление при подтверждении |
| 477 | + .PARAMETER UpdateInfo |
| 478 | + Хэштаблица с информацией об обновлении от Test-ScriptUpdate |
| 479 | + #> |
| 480 | + param( |
| 481 | + [Parameter(Mandatory)] |
| 482 | + [hashtable]$UpdateInfo |
| 483 | + ) |
| 484 | + |
| 485 | + Write-Host "" |
| 486 | + Write-Host " ╔══════════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan |
| 487 | + Write-Host " ║ " -NoNewline -ForegroundColor Cyan |
| 488 | + Write-Host "UPDATE AVAILABLE" -NoNewline -ForegroundColor Yellow |
| 489 | + Write-Host " ║" -ForegroundColor Cyan |
| 490 | + Write-Host " ╚══════════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan |
| 491 | + Write-Host "" |
| 492 | + Write-Host " Current version: " -NoNewline -ForegroundColor Gray |
| 493 | + Write-Host "v$($UpdateInfo.CurrentVersion)" -ForegroundColor White |
| 494 | + Write-Host " Latest version: " -NoNewline -ForegroundColor Gray |
| 495 | + Write-Host "v$($UpdateInfo.LatestVersion)" -NoNewline -ForegroundColor Green |
| 496 | + Write-Host " (new)" -ForegroundColor DarkGreen |
| 497 | + Write-Host "" |
| 498 | + |
| 499 | + Write-Log "Update available: v$($UpdateInfo.CurrentVersion) -> v$($UpdateInfo.LatestVersion)" -Level INFO |
| 500 | + |
| 501 | + # In ReportOnly mode, just inform and continue |
| 502 | + if ($ReportOnly) { |
| 503 | + Write-Host " ReportOnly mode - skipping update" -ForegroundColor DarkGray |
| 504 | + Write-Host "" |
| 505 | + return |
| 506 | + } |
| 507 | + |
| 508 | + # Check if interactive console is available |
| 509 | + if (-not (Test-InteractiveConsole)) { |
| 510 | + Write-Host " Non-interactive mode - skipping update prompt" -ForegroundColor DarkGray |
| 511 | + Write-Host " To update manually: Update-Script -Name WinClean" -ForegroundColor Gray |
| 512 | + Write-Host "" |
| 513 | + return |
| 514 | + } |
| 515 | + |
| 516 | + if ($UpdateInfo.IsInstalled) { |
| 517 | + # Installed via PSGallery - can auto-update |
| 518 | + Write-Host " Update now? (" -NoNewline -ForegroundColor Gray |
| 519 | + Write-Host "Y" -NoNewline -ForegroundColor Green |
| 520 | + Write-Host "/n): " -NoNewline -ForegroundColor Gray |
| 521 | + |
| 522 | + $response = Read-Host |
| 523 | + if ($response -eq '' -or $response -imatch '^[YyДд]') { |
| 524 | + Write-Host "" |
| 525 | + Write-Host " Updating WinClean..." -ForegroundColor Cyan |
| 526 | + |
| 527 | + try { |
| 528 | + Update-Script -Name WinClean -Force -ErrorAction Stop |
| 529 | + Write-Log "Update successful" -Level SUCCESS |
| 530 | + Write-Host "" |
| 531 | + Write-Host " ✓ Update complete!" -ForegroundColor Green |
| 532 | + Write-Host " Please run WinClean again to use the new version." -ForegroundColor Gray |
| 533 | + Write-Host "" |
| 534 | + Write-Host " Press any key to exit..." -ForegroundColor DarkGray |
| 535 | + $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") |
| 536 | + exit 0 |
| 537 | + } catch { |
| 538 | + Write-Log "Update failed: $_" -Level ERROR |
| 539 | + Write-Host " ✗ Update failed: $_" -ForegroundColor Red |
| 540 | + Write-Host " Continuing with current version..." -ForegroundColor Yellow |
| 541 | + Write-Host "" |
| 542 | + } |
| 543 | + } else { |
| 544 | + Write-Log "Update skipped by user" -Level INFO |
| 545 | + Write-Host " Update skipped. Continuing with current version..." -ForegroundColor DarkGray |
| 546 | + Write-Host "" |
| 547 | + } |
| 548 | + } else { |
| 549 | + # Not installed via PSGallery - show manual instructions |
| 550 | + Write-Host " WinClean was not installed via PowerShell Gallery." -ForegroundColor Yellow |
| 551 | + Write-Host " To enable auto-updates, install with:" -ForegroundColor Gray |
| 552 | + Write-Host "" |
| 553 | + Write-Host " Install-Script -Name WinClean -Scope CurrentUser -Force" -ForegroundColor White |
| 554 | + Write-Host "" |
| 555 | + Write-Host " Press any key to continue with current version..." -ForegroundColor DarkGray |
| 556 | + $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") |
| 557 | + Write-Host "" |
| 558 | + } |
| 559 | +} |
| 560 | + |
421 | 561 | function Install-ModuleWithTimeout { |
422 | 562 | <# |
423 | 563 | .SYNOPSIS |
@@ -2480,6 +2620,12 @@ function Start-WinClean { |
2480 | 2620 | Write-Host "" |
2481 | 2621 | } |
2482 | 2622 |
|
| 2623 | + # Check for script updates |
| 2624 | + $updateInfo = Test-ScriptUpdate |
| 2625 | + if ($updateInfo) { |
| 2626 | + Invoke-ScriptUpdate -UpdateInfo $updateInfo |
| 2627 | + } |
| 2628 | + |
2483 | 2629 | try { |
2484 | 2630 | # Phase 1: Preparation |
2485 | 2631 | $null = New-SystemRestorePoint -Description "WinClean $(Get-Date -Format 'yyyy-MM-dd HH:mm')" |
|
0 commit comments