Skip to content

Commit 89ad219

Browse files
bivlkedclaude
andcommitted
feat: add auto-update check at startup (v2.10)
- Add Test-ScriptUpdate function to check PSGallery for newer version - Add Invoke-ScriptUpdate function to prompt user and perform update - Update check runs after reboot check, before main operations - Shows manual install instructions if script downloaded manually - Respects ReportOnly mode and non-interactive environments - Update version to 2.10 in all references - Update CHANGELOG.md with v2.10 entry Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a8e9002 commit 89ad219

4 files changed

Lines changed: 172 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
---
99

10+
## [2.10] - 2026-01-17
11+
12+
### Added
13+
- **Auto-update check at startup**: Script now checks PowerShell Gallery for newer version
14+
- Runs after reboot check, before main operations
15+
- Shows current vs available version with visual comparison
16+
- Prompts user to update if newer version available
17+
- Performs update via `Update-Script` if user confirms
18+
- Shows manual installation instructions if script was downloaded manually (not via PSGallery)
19+
- Respects `-ReportOnly` mode (informs but doesn't update)
20+
- Gracefully skips in non-interactive environments
21+
22+
### Technical
23+
- `Test-ScriptUpdate` function: compares `$script:Version` with PSGallery version
24+
- `Invoke-ScriptUpdate` function: handles UI, user prompt, and update execution
25+
- Uses existing `Test-PSGalleryConnection` for connectivity check
26+
27+
---
28+
1029
## [2.9] - 2026-01-17
1130

1231
### Fixed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### Ultimate Windows 11 Maintenance Script
88

9-
[![Version](https://img.shields.io/badge/version-2.9-blue.svg)](https://github.com/bivlked/WinClean/releases)
9+
[![Version](https://img.shields.io/badge/version-2.10-blue.svg)](https://github.com/bivlked/WinClean/releases)
1010
[![PSGallery](https://img.shields.io/powershellgallery/v/WinClean?label=PSGallery&logo=powershell&logoColor=white)](https://www.powershellgallery.com/packages/WinClean)
1111
[![CI](https://github.com/bivlked/WinClean/actions/workflows/ci.yml/badge.svg)](https://github.com/bivlked/WinClean/actions/workflows/ci.yml)
1212
[![PowerShell 7.1+](https://img.shields.io/badge/PowerShell-7.1%2B-5391FE?logo=powershell&logoColor=white)](https://github.com/PowerShell/PowerShell)
@@ -319,7 +319,7 @@ C:\Users\YourName\
319319

320320
```
321321
┌────────────────────────────────────────────────────────────────┐
322-
│ WinClean v2.9
322+
│ WinClean v2.10
323323
├────────────────────────────────────────────────────────────────┤
324324
│ PREPARATION │
325325
│ ├─ ✓ Check Administrator Rights │

README_RU.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### Комплексный скрипт обслуживания Windows 11
88

9-
[![Версия](https://img.shields.io/badge/версия-2.9-blue.svg)](https://github.com/bivlked/WinClean/releases)
9+
[![Версия](https://img.shields.io/badge/версия-2.10-blue.svg)](https://github.com/bivlked/WinClean/releases)
1010
[![PSGallery](https://img.shields.io/powershellgallery/v/WinClean?label=PSGallery&logo=powershell&logoColor=white)](https://www.powershellgallery.com/packages/WinClean)
1111
[![CI](https://github.com/bivlked/WinClean/actions/workflows/ci.yml/badge.svg)](https://github.com/bivlked/WinClean/actions/workflows/ci.yml)
1212
[![PowerShell 7.1+](https://img.shields.io/badge/PowerShell-7.1%2B-5391FE?logo=powershell&logoColor=white)](https://github.com/PowerShell/PowerShell)
@@ -319,7 +319,7 @@ C:\Users\ВашеИмя\
319319

320320
```
321321
┌────────────────────────────────────────────────────────────────┐
322-
│ WinClean v2.9
322+
│ WinClean v2.10
323323
├────────────────────────────────────────────────────────────────┤
324324
│ ПОДГОТОВКА │
325325
│ ├─ ✓ Проверка прав администратора │

WinClean.ps1

Lines changed: 149 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<#PSScriptInfo
2-
.VERSION 2.9
2+
.VERSION 2.10
33
.GUID 8f7c3b2a-1d4e-5f6a-9b8c-0d1e2f3a4b5c
44
.AUTHOR bivlked
55
.COMPANYNAME
@@ -12,6 +12,7 @@
1212
.REQUIREDSCRIPTS
1313
.EXTERNALSCRIPTDEPENDENCIES
1414
.RELEASENOTES
15+
v2.10: Added auto-update check at startup (checks PSGallery for new version)
1516
v2.9: Fixed PSWindowsUpdate installation hanging (TLS 1.2, timeouts)
1617
v2.8: Fixed Disk Cleanup timeout issues
1718
v2.7: UI improvements for final statistics
@@ -20,7 +21,7 @@
2021

2122
<#
2223
.SYNOPSIS
23-
WinClean - Ultimate Windows 11 Maintenance Script v2.9
24+
WinClean - Ultimate Windows 11 Maintenance Script v2.10
2425
.DESCRIPTION
2526
Комплексный скрипт для обновления и очистки Windows 11:
2627
- Обновление Windows (включая драйверы)
@@ -34,8 +35,15 @@
3435
- Подробный цветной вывод + лог-файл
3536
.NOTES
3637
Author: biv
37-
Version: 2.9
38+
Version: 2.10
3839
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
3947
Changes in 2.9:
4048
- Fixed PSWindowsUpdate installation hanging: added TLS 1.2 enforcement
4149
- Added Test-PSGalleryConnection function: pre-checks PowerShell Gallery availability
@@ -196,6 +204,9 @@ if (-not $LogPath) {
196204
$script:LogPath = $LogPath
197205
}
198206

207+
# Script version (single source of truth for version checking)
208+
$script:Version = "2.10"
209+
199210
# Protected paths that should never be deleted
200211
$script:ProtectedPaths = @(
201212
$env:SystemRoot,
@@ -418,6 +429,135 @@ function Test-PSGalleryConnection {
418429
}
419430
}
420431

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+
421561
function Install-ModuleWithTimeout {
422562
<#
423563
.SYNOPSIS
@@ -2480,6 +2620,12 @@ function Start-WinClean {
24802620
Write-Host ""
24812621
}
24822622

2623+
# Check for script updates
2624+
$updateInfo = Test-ScriptUpdate
2625+
if ($updateInfo) {
2626+
Invoke-ScriptUpdate -UpdateInfo $updateInfo
2627+
}
2628+
24832629
try {
24842630
# Phase 1: Preparation
24852631
$null = New-SystemRestorePoint -Description "WinClean $(Get-Date -Format 'yyyy-MM-dd HH:mm')"

0 commit comments

Comments
 (0)