This repository was archived by the owner on Dec 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinget-update.ps1
More file actions
2666 lines (2283 loc) · 117 KB
/
Copy pathwinget-update.ps1
File metadata and controls
2666 lines (2283 loc) · 117 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.SYNOPSIS
Advanced PowerShell script for updating applications using winget.
.DESCRIPTION
This script automates the process of updating applications
using the Windows Package Manager (winget). It offers various operation modes,
application exclusion capabilities, and custom parameter support for winget.
.NOTES
File Name : winget-update.ps1
Author : sterbweise
Prerequisite : PowerShell 5.1 or later, Windows Package Manager (winget)
Version : v3.1.0
Date : 2025-07-26
_ _ _ _ _ _ _ _
| | | (_) | | | | | | | | | |
| | | |_ _ __ __ _ ___| |_ | | | |_ __ __| | __ _| |_ ___
| |/\| | | '_ \ / _` |/ _ \ __| | | | | '_ \ / _` |/ _` | __/ _ \
\ /\ / | | | | (_| | __/ |_ | |_| | |_) | (_| | (_| | || __/
\/ \/|_|_| |_|\__, |\___|\__| \___/| .__/ \__,_|\__,_|\__\___|
__/ | | |
|___/ |_|
"Elevating your system's potential, one update at a time."
#>
# Define script parameters
param(
[Parameter(Mandatory=$false)]
[Alias("e", "exclude")]
[string[]]$ExcludeApps = @(),
[Parameter(Mandatory=$false)]
[Alias("m")]
[ValidateSet("normal", "silent", "force", "verbose", "no-interaction", "full-upgrade", "safe-upgrade", "dry-run")]
[string]$Mode = "normal",
[Parameter(Mandatory=$false)]
[Alias("ape", "add-persistent-exclude")]
[string[]]$AddPersistentExcludeApps = @(),
[Parameter(Mandatory=$false)]
[Alias("rpe", "remove-persistent-exclude")]
[string[]]$RemovePersistentExcludeApps = @(),
[Parameter(Mandatory=$false)]
[Alias("cp", "custom-params")]
[string]$CustomParams = "",
[Parameter(Mandatory=$false)]
[switch]$Help
)
# Check if running as administrator
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# Require administrator privileges for package updates
if (-not $Help -and -not (Test-Administrator)) {
Write-Host ""
Write-Host "⚠️ Administrator privileges required" -ForegroundColor Yellow
Write-Host ""
Write-Host "This script requires administrator privileges to update system packages." -ForegroundColor White
Write-Host "Please run PowerShell as Administrator and try again." -ForegroundColor White
Write-Host ""
Write-Host "Right-click PowerShell → 'Run as Administrator'" -ForegroundColor DarkGray
Write-Host ""
exit 1
}
# Define the path for the persistent exclude list file
$PersistentExcludeFile = Join-Path $PSScriptRoot "persistent_exclude_apps.txt"
# Create required directories and files
$requiredPaths = @(
(Join-Path $PSScriptRoot "logs"),
(Join-Path $PSScriptRoot "reports"),
(Join-Path $PSScriptRoot "config")
)
foreach ($path in $requiredPaths) {
if (-not (Test-Path $path)) {
New-Item -ItemType Directory -Path $path -Force | Out-Null
}
}
# Create the persistent exclude file if it doesn't exist
if (-not (Test-Path $PersistentExcludeFile)) {
New-Item -Path $PersistentExcludeFile -ItemType File -Force | Out-Null
Write-Host "✅ Created persistent exclude file: $PersistentExcludeFile" -ForegroundColor Green
}
# Function to clean old log files
function Clear-OldLogs {
param([int]$RetentionDays = 30)
$logDir = Join-Path $PSScriptRoot "logs"
if (Test-Path $logDir) {
$cutoffDate = (Get-Date).AddDays(-$RetentionDays)
$oldLogs = @(Get-ChildItem $logDir -Filter "*.log" | Where-Object { $_.LastWriteTime -lt $cutoffDate })
if ($oldLogs.Count -gt 0) {
$oldLogs | Remove-Item -Force
Write-Host "🧹 Cleaned $($oldLogs.Count) old log files (older than $RetentionDays days)" -ForegroundColor Yellow
}
}
}
# Clean old logs on startup
Clear-OldLogs
# Function to display comprehensive help information
function Show-Help {
# Get console width for better formatting
$width = [Math]::Min(120, $Host.UI.RawUI.WindowSize.Width - 2)
$width = [Math]::Max(40, $width) # Ensure minimum width
# Safe string creation
$separator = ""
$doubleSeparator = ""
$thinSeparator = ""
for ($i = 0; $i -lt $width; $i++) {
$separator += "─"
$doubleSeparator += "═"
$thinSeparator += "┄"
}
function Write-CenteredText {
param(
[string]$Text,
[string]$Color = "White",
[switch]$NoNewline
)
$spaces = " " * [Math]::Max(0, [Math]::Floor(($width - $Text.Length) / 2))
if ($NoNewline) {
Write-Host ($spaces + $Text) -ForegroundColor $Color -NoNewline
} else {
Write-Host ($spaces + $Text) -ForegroundColor $Color
}
}
function Write-Section {
param(
[string]$Title,
[string]$Icon,
[string]$Color = "Cyan"
)
Write-Host ""
Write-Host "$Icon $Title" -ForegroundColor $Color
Write-Host $separator -ForegroundColor DarkGray
}
function Write-Parameter {
param(
[string]$Name,
[string]$Aliases,
[string]$Type,
[string]$Description,
[string]$Example,
[string]$Notes = ""
)
Write-Host " " -NoNewline
Write-Host $Name -ForegroundColor Green -NoNewline
if ($Aliases) {
Write-Host ", " -NoNewline -ForegroundColor DarkGray
Write-Host $Aliases -ForegroundColor Yellow
} else {
Write-Host ""
}
Write-Host " Type: " -NoNewline -ForegroundColor DarkGray
Write-Host $Type -ForegroundColor Magenta
Write-Host " $Description" -ForegroundColor White
Write-Host " Example: " -NoNewline -ForegroundColor DarkGray
Write-Host $Example -ForegroundColor DarkCyan
if ($Notes) {
Write-Host " Note: " -NoNewline -ForegroundColor DarkYellow
Write-Host $Notes -ForegroundColor Yellow
}
Write-Host ""
}
Clear-Host
# Header Banner with perfect alignment
Write-Host "╔$doubleSeparator╗" -ForegroundColor Magenta
# First line with title
$title1 = "WINGET UPDATE MANAGER v3.1.0"
$padding1 = $width - $title1.Length
$leftPad1 = [Math]::Max(0, [Math]::Floor($padding1 / 2))
$rightPad1 = [Math]::Max(0, $padding1 - $leftPad1)
Write-Host "║" -NoNewline -ForegroundColor Magenta
for ($i = 0; $i -lt $leftPad1; $i++) { Write-Host " " -NoNewline }
Write-Host $title1 -NoNewline -ForegroundColor White
for ($i = 0; $i -lt $rightPad1; $i++) { Write-Host " " -NoNewline }
Write-Host "║" -ForegroundColor Magenta
# Second line with subtitle
$title2 = "Advanced Windows Package Management Solution"
$padding2 = [Math]::Max(0, $width - $title2.Length)
$leftPad2 = [Math]::Max(0, [Math]::Floor($padding2 / 2))
$rightPad2 = [Math]::Max(0, $padding2 - $leftPad2)
Write-Host "║" -NoNewline -ForegroundColor Magenta
for ($i = 0; $i -lt $leftPad2; $i++) { Write-Host " " -NoNewline }
Write-Host $title2 -NoNewline -ForegroundColor DarkCyan
for ($i = 0; $i -lt $rightPad2; $i++) { Write-Host " " -NoNewline }
Write-Host "║" -ForegroundColor Magenta
Write-Host "╚$doubleSeparator╝" -ForegroundColor Magenta
# Synopsis
Write-Section "SYNOPSIS" "🎯" "Yellow"
Write-Host " Professional-grade PowerShell script for automated Windows application management" -ForegroundColor White
Write-Host " using Windows Package Manager (winget). Features intelligent application detection," -ForegroundColor White
Write-Host " smart exclusion management, multiple operation modes, comprehensive logging," -ForegroundColor White
Write-Host " and enterprise-ready automation capabilities." -ForegroundColor White
# Syntax
Write-Section "SYNTAX" "📋" "Yellow"
Write-Host " Basic Update Operations:" -ForegroundColor Cyan
Write-Host " .\winget-update.ps1 [-Mode <String>] [-ExcludeApps <String[]>] [-CustomParams <String>]" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Persistent Exclusion Management:" -ForegroundColor Cyan
Write-Host " .\winget-update.ps1 -AddPersistentExcludeApps <String[]>" -ForegroundColor DarkGray
Write-Host " .\winget-update.ps1 -RemovePersistentExcludeApps <String[]>" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Information & Help:" -ForegroundColor Cyan
Write-Host " .\winget-update.ps1 -Help" -ForegroundColor DarkGray
# Parameters
Write-Section "PARAMETERS" "⚙️" "Yellow"
Write-Parameter -Name "-Mode" -Aliases "-m" -Type "String" `
-Description "Specifies the update execution mode. Controls behavior, interaction level, and safety measures." `
-Example ".\winget-update.ps1 -Mode silent" `
-Notes "See UPDATE MODES section for detailed mode descriptions"
Write-Parameter -Name "-ExcludeApps" -Aliases "-e, -exclude" -Type "String[]" `
-Description "Temporarily excludes specified applications from the current update session only." `
-Example ".\winget-update.ps1 -ExcludeApps `"Microsoft.Edge,Mozilla.Firefox`"" `
-Notes "Supports both application names and IDs. Use comma separation for multiple apps."
Write-Parameter -Name "-AddPersistentExcludeApps" -Aliases "-ape, -add-persistent-exclude" -Type "String[]" `
-Description "🧠 INTELLIGENT: Adds applications to permanent exclusion list with smart detection." `
-Example ".\winget-update.ps1 -ape `"Visual Studio Code,Chrome`"" `
-Notes "Auto-detects installed apps, converts names to IDs, suggests matches if ambiguous"
Write-Parameter -Name "-RemovePersistentExcludeApps" -Aliases "-rpe, -remove-persistent-exclude" -Type "String[]" `
-Description "🧠 INTELLIGENT: Removes applications from permanent exclusion list with smart matching." `
-Example ".\winget-update.ps1 -rpe `"Wireshark,Discord`"" `
-Notes "Finds matches by name or ID, shows friendly names, suggests alternatives"
Write-Parameter -Name "-CustomParams" -Aliases "-cp" -Type "String" `
-Description "Passes additional parameters directly to winget upgrade command." `
-Example ".\winget-update.ps1 -CustomParams `"--include-unknown --force`"" `
-Notes "Advanced users only. Refer to winget upgrade --help for available options"
Write-Parameter -Name "-Help" -Aliases "" -Type "Switch" `
-Description "Displays this comprehensive help documentation." `
-Example ".\winget-update.ps1 -Help"
# Update Modes
Write-Section "UPDATE MODES" "🔄" "Yellow"
Write-Host " The script supports multiple execution modes for different scenarios:" -ForegroundColor White
Write-Host ""
$modes = @(
@{ Name = "normal"; Icon = "🔵"; Description = "Default interactive mode with user prompts and confirmations"; Use = "General use, manual updates" },
@{ Name = "silent"; Icon = "🔇"; Description = "Automated mode with minimal output, accepts all agreements"; Use = "Scheduled tasks, CI/CD pipelines" },
@{ Name = "force"; Icon = "⚡"; Description = "Aggressive mode bypassing restrictions and warnings"; Use = "Emergency updates, troubleshooting" },
@{ Name = "verbose"; Icon = "📝"; Description = "Detailed logging with comprehensive diagnostic information"; Use = "Debugging, issue reporting" },
@{ Name = "no-interaction"; Icon = "🤖"; Description = "Zero user interaction, fully automated execution"; Use = "Server environments, automation" },
@{ Name = "full-upgrade"; Icon = "🔄"; Description = "Includes unknown versions and pinned packages"; Use = "Complete system refresh" },
@{ Name = "safe-upgrade"; Icon = "🛡️"; Description = "Conservative approach with enhanced safety checks"; Use = "Production systems, critical environments" },
@{ Name = "dry-run"; Icon = "🔍"; Description = "Simulation mode showing planned actions without execution"; Use = "Testing, planning, verification" }
)
foreach ($mode in $modes) {
Write-Host " $($mode.Icon) " -NoNewline -ForegroundColor White
Write-Host $mode.Name -NoNewline -ForegroundColor Green
Write-Host " - " -NoNewline -ForegroundColor DarkGray
Write-Host $mode.Description -ForegroundColor White
Write-Host " Use case: " -NoNewline -ForegroundColor DarkGray
Write-Host $mode.Use -ForegroundColor DarkCyan
Write-Host ""
}
# Smart Features
Write-Section "🧠 INTELLIGENT FEATURES" "🤖" "Magenta"
Write-Host " Advanced capabilities that make this script enterprise-ready:" -ForegroundColor White
Write-Host ""
Write-Host " 🔍 Smart Application Detection" -ForegroundColor Green
Write-Host " • Automatically scans installed applications" -ForegroundColor DarkGray
Write-Host " • Matches application names to official IDs" -ForegroundColor DarkGray
Write-Host " • Provides suggestions for partial matches" -ForegroundColor DarkGray
Write-Host ""
Write-Host " 🎯 Intelligent Exclusion Management" -ForegroundColor Green
Write-Host " • Converts friendly names to precise IDs automatically" -ForegroundColor DarkGray
Write-Host " • Handles ambiguous matches with user-friendly suggestions" -ForegroundColor DarkGray
Write-Host " • Cross-references with installed applications database" -ForegroundColor DarkGray
Write-Host ""
Write-Host " � Professeional Reporting" -ForegroundColor Green
Write-Host " • Comprehensive update summaries with statistics" -ForegroundColor DarkGray
Write-Host " • Detailed logging with timestamps and session IDs" -ForegroundColor DarkGray
Write-Host " • Color-coded status indicators and progress tracking" -ForegroundColor DarkGray
Write-Host ""
# Examples
Write-Section "EXAMPLES" "📚" "Yellow"
$examples = @(
@{
Title = "Basic Operations"
Commands = @(
@{ Cmd = ".\winget-update.ps1"; Desc = "Standard update with default settings" },
@{ Cmd = ".\winget-update.ps1 -Mode dry-run"; Desc = "Preview updates without installing" },
@{ Cmd = ".\winget-update.ps1 -Mode silent"; Desc = "Automated silent update" }
)
},
@{
Title = "Exclusion Management"
Commands = @(
@{ Cmd = ".\winget-update.ps1 -e `"Microsoft.Edge,Discord`""; Desc = "Exclude apps from current session" },
@{ Cmd = ".\winget-update.ps1 -ape `"Visual Studio Code`""; Desc = "Add app to permanent exclusion (smart detection)" },
@{ Cmd = ".\winget-update.ps1 -rpe `"Chrome`""; Desc = "Remove app from permanent exclusion (smart matching)" }
)
},
@{
Title = "Advanced Usage"
Commands = @(
@{ Cmd = ".\winget-update.ps1 -Mode force -cp `"--include-unknown`""; Desc = "Force update including unknown versions" },
@{ Cmd = ".\winget-update.ps1 -Mode verbose -e `"App1,App2`""; Desc = "Detailed logging with specific exclusions" },
@{ Cmd = ".\winget-update.ps1 -Mode no-interaction"; Desc = "Fully automated execution for servers" }
)
},
@{
Title = "Smart Exclusion Examples"
Commands = @(
@{ Cmd = ".\winget-update.ps1 -ape `"Wireshark`""; Desc = "Finds: WiresharkFoundation.Wireshark automatically" },
@{ Cmd = ".\winget-update.ps1 -ape `"Chrome`""; Desc = "Shows multiple matches: Google.Chrome, etc." },
@{ Cmd = ".\winget-update.ps1 -rpe `"Visual Studio`""; Desc = "Smart removal with friendly name display" }
)
}
)
foreach ($exampleGroup in $examples) {
Write-Host " $($exampleGroup.Title):" -ForegroundColor Cyan
foreach ($example in $exampleGroup.Commands) {
Write-Host " 📎 " -NoNewline -ForegroundColor DarkGray
Write-Host $example.Cmd -ForegroundColor DarkCyan
Write-Host " $($example.Desc)" -ForegroundColor White
}
Write-Host ""
}
# File Structure
Write-Section "FILE STRUCTURE" "📁" "Yellow"
Write-Host " The script creates and manages the following files and directories:" -ForegroundColor White
Write-Host ""
Write-Host " 📄 persistent_exclude_apps.txt" -ForegroundColor Green
Write-Host " Contains permanently excluded application IDs" -ForegroundColor DarkGray
Write-Host ""
Write-Host " 📁 logs/" -ForegroundColor Green
Write-Host " ├── winget_update_YYYY-MM-DD_HH-MM-SS.log (Standard logs)" -ForegroundColor DarkGray
Write-Host " └── winget_update_YYYY-MM-DD_HH-MM-SS_ID.log (Session-specific logs)" -ForegroundColor DarkGray
Write-Host ""
Write-Host " 📁 backup/" -ForegroundColor Green
Write-Host " Automatic backups of configuration files" -ForegroundColor DarkGray
Write-Host ""
Write-Host " 📁 logs/" -ForegroundColor Green
Write-Host " └── winget_update_*.log (Logs des mises à jour)" -ForegroundColor DarkGray
# Requirements
Write-Section "REQUIREMENTS" "🔧" "Yellow"
Write-Host " System Requirements:" -ForegroundColor Cyan
Write-Host " • Windows 10 version 1809 (build 17763) or later" -ForegroundColor White
Write-Host " • PowerShell 5.1 or PowerShell 7+" -ForegroundColor White
Write-Host " • Windows Package Manager (winget) installed and configured" -ForegroundColor White
Write-Host " • Administrator privileges (recommended for system-wide updates)" -ForegroundColor White
Write-Host ""
Write-Host " Optional Components:" -ForegroundColor Cyan
Write-Host " • Windows Terminal (for enhanced display)" -ForegroundColor DarkGray
Write-Host " • Git (for version checking and updates)" -ForegroundColor DarkGray
# Troubleshooting
Write-Section "TROUBLESHOOTING" "🔧" "Yellow"
Write-Host " Common Issues and Solutions:" -ForegroundColor White
Write-Host ""
Write-Host " 🚫 'winget' is not recognized" -ForegroundColor Red
Write-Host " Solution: Install Windows Package Manager from Microsoft Store" -ForegroundColor Green
Write-Host ""
Write-Host " 🚫 Access denied errors" -ForegroundColor Red
Write-Host " Solution: Run PowerShell as Administrator" -ForegroundColor Green
Write-Host ""
Write-Host " 🚫 Script execution policy errors" -ForegroundColor Red
Write-Host " Solution: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser" -ForegroundColor Green
Write-Host ""
Write-Host " 🚫 Application not found in smart detection" -ForegroundColor Red
Write-Host " Solution: Ensure application is installed via winget, try exact ID instead" -ForegroundColor Green
# Footer with perfect alignment
Write-Host ""
Write-Host "╔$doubleSeparator╗" -ForegroundColor DarkGray
# System Information header
$sysInfoTitle = "SYSTEM INFORMATION"
$sysInfoPadding = [Math]::Max(0, $width - $sysInfoTitle.Length)
$sysInfoLeftPad = [Math]::Max(0, [Math]::Floor($sysInfoPadding / 2))
$sysInfoRightPad = [Math]::Max(0, $sysInfoPadding - $sysInfoLeftPad)
Write-Host "║" -NoNewline -ForegroundColor DarkGray
for ($i = 0; $i -lt $sysInfoLeftPad; $i++) { Write-Host " " -NoNewline }
Write-Host $sysInfoTitle -NoNewline -ForegroundColor White
for ($i = 0; $i -lt $sysInfoRightPad; $i++) { Write-Host " " -NoNewline }
Write-Host "║" -ForegroundColor DarkGray
# Version line
$versionText = " Version: v3.1.0"
$versionPadding = [Math]::Max(0, $width - $versionText.Length)
Write-Host "║" -NoNewline -ForegroundColor DarkGray
Write-Host " Version: " -NoNewline -ForegroundColor DarkGray
Write-Host "v3.1.0" -NoNewline -ForegroundColor Green
for ($i = 0; $i -lt $versionPadding; $i++) { Write-Host " " -NoNewline }
Write-Host "║" -ForegroundColor DarkGray
# Author line
$authorText = " Author: Sterbweise"
$authorPadding = [math]::Max(0, $width - $authorText.Length)
Write-Host "║" -NoNewline -ForegroundColor DarkGray
Write-Host " Author: " -NoNewline -ForegroundColor DarkGray
Write-Host "Sterbweise" -NoNewline -ForegroundColor Yellow
if ($authorPadding -gt 0) {
for ($i = 0; $i -lt $authorPadding; $i++) { Write-Host " " -NoNewline }
}
Write-Host "║" -ForegroundColor DarkGray
# License line
$licenseText = " License: MIT"
$licensePadding = [math]::Max(0, $width - $licenseText.Length)
Write-Host "║" -NoNewline -ForegroundColor DarkGray
Write-Host " License: " -NoNewline -ForegroundColor DarkGray
Write-Host "MIT" -NoNewline -ForegroundColor Green
if ($licensePadding -gt 0) {
for ($i = 0; $i -lt $licensePadding; $i++) { Write-Host " " -NoNewline }
}
Write-Host "║" -ForegroundColor DarkGray
# Repository line
$repoLine = " Repository: https://github.com/Sterbweise/winget-update"
$repoPadding = [math]::Max(0, $width - $repoLine.Length)
Write-Host "║" -NoNewline -ForegroundColor DarkGray
Write-Host " Repository: " -NoNewline -ForegroundColor DarkGray
Write-Host "https://github.com/Sterbweise/winget-update" -NoNewline -ForegroundColor Blue
if ($repoPadding -gt 0) {
for ($i = 0; $i -lt $repoPadding; $i++) { Write-Host " " -NoNewline }
}
Write-Host "║" -ForegroundColor DarkGray
# Last Updated line
$updateLine = " Last Updated: July 20, 2025"
$updatePadding = [math]::Max(0, $width - $updateLine.Length)
Write-Host "║" -NoNewline -ForegroundColor DarkGray
Write-Host " Last Updated: " -NoNewline -ForegroundColor DarkGray
Write-Host "July 20, 2025" -NoNewline -ForegroundColor Magenta
if ($updatePadding -gt 0) {
for ($i = 0; $i -lt $updatePadding; $i++) { Write-Host " " -NoNewline }
}
Write-Host "║" -ForegroundColor DarkGray
Write-Host "╚$doubleSeparator╝" -ForegroundColor DarkGray
Write-Host ""
Write-CenteredText "Press any key to exit help and return to terminal..." "DarkYellow"
Write-Host ""
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
}
# Display help if requested
if ($Help) {
Show-Help
}
# Function to retrieve the persistent exclude list
function Get-PersistentExcludeList {
if (Test-Path $PersistentExcludeFile) {
$content = Get-Content $PersistentExcludeFile -ErrorAction SilentlyContinue
if ($content) {
return @($content | Where-Object { $_.Trim() -ne "" })
}
}
return @()
}
# Function to get installed applications for smart suggestions
function Get-InstalledApplications {
try {
$installedApps = @()
# Get winget list output
$wingetOutput = winget list --accept-source-agreements 2>$null
if ($wingetOutput) {
# Parse winget output (skip header lines)
$lines = $wingetOutput | Select-Object -Skip 2
foreach ($line in $lines) {
if ($line -and $line.Trim() -ne "" -and $line -notmatch "^-+") {
# Parse the line to extract Name and Id
$parts = $line -split '\s{2,}' # Split on multiple spaces
if ($parts.Count -ge 2) {
$name = $parts[0].Trim()
$id = $parts[1].Trim()
if ($name -and $id -and $id -notmatch "^Available|^Upgrades") {
$installedApps += [PSCustomObject]@{
Name = $name
Id = $id
}
}
}
}
}
}
return $installedApps
} catch {
Write-Host "⚠️ Warning: Could not retrieve installed applications list." -ForegroundColor Yellow
return @()
}
}
# Function to find application suggestions
function Find-ApplicationSuggestions {
param(
[string]$SearchTerm,
[array]$InstalledApps
)
$suggestions = @()
# Ensure InstalledApps is an array
if (-not $InstalledApps) {
return @()
}
$InstalledApps = @($InstalledApps)
# Exact name match
$exactNameMatch = $InstalledApps | Where-Object { $_.Name -eq $SearchTerm }
if ($exactNameMatch) {
return @($exactNameMatch)
}
# Exact ID match
$exactIdMatch = $InstalledApps | Where-Object { $_.Id -eq $SearchTerm }
if ($exactIdMatch) {
return @($exactIdMatch)
}
# Partial name matches (case insensitive)
$nameMatches = @($InstalledApps | Where-Object { $_.Name -like "*$SearchTerm*" })
$suggestions += $nameMatches
# Partial ID matches (case insensitive)
$idMatches = @($InstalledApps | Where-Object { $_.Id -like "*$SearchTerm*" })
$suggestions += $idMatches
# Remove duplicates
$uniqueSuggestions = @()
foreach ($suggestion in $suggestions) {
$exists = $false
foreach ($unique in $uniqueSuggestions) {
if ($unique.Id -eq $suggestion.Id) {
$exists = $true
break
}
}
if (-not $exists) {
$uniqueSuggestions += $suggestion
}
}
return $uniqueSuggestions | Select-Object -First 10 # Limit to 10 suggestions
}
# Enhanced function to add applications to the persistent exclude list with smart suggestions
function Add-PersistentExcludeApps {
param(
[string[]]$Apps
)
if (-not $Apps -or $Apps.Count -eq 0) {
Write-Host "❌ No applications specified to add to the persistent exclude list." -ForegroundColor Red
return
}
Write-Host "🔍 Analyzing installed applications..." -ForegroundColor Cyan
$installedApps = @(Get-InstalledApplications)
if (-not $installedApps -or $installedApps.Count -eq 0) {
Write-Host "⚠️ Warning: Could not retrieve installed applications list." -ForegroundColor Yellow
Write-Host " 💡 Make sure winget is working properly: winget list" -ForegroundColor DarkGray
return
}
$currentList = @(Get-PersistentExcludeList)
$validAppsToAdd = @()
foreach ($app in $Apps) {
if ($currentList -contains $app) {
Write-Host "ℹ️ '$app' is already in the persistent exclude list." -ForegroundColor Yellow
continue
}
# Find suggestions for this app
$suggestions = @(Find-ApplicationSuggestions -SearchTerm $app -InstalledApps $installedApps)
if (-not $suggestions -or $suggestions.Count -eq 0) {
Write-Host "❌ No installed application found matching '$app'." -ForegroundColor Red
Write-Host " 💡 Make sure the application is installed and try using the exact name or ID." -ForegroundColor DarkGray
continue
}
if ($suggestions -and $suggestions.Count -eq 1) {
# Exact match found - use the ID
$selectedApp = $suggestions[0]
$appToAdd = $selectedApp.Id
Write-Host "✅ Found exact match for '$app':" -ForegroundColor Green
Write-Host " 📦 Name: $($selectedApp.Name)" -ForegroundColor White
Write-Host " 🆔 ID: $($selectedApp.Id)" -ForegroundColor Cyan
Write-Host " ➕ Adding ID to exclude list..." -ForegroundColor DarkGray
$validAppsToAdd += $appToAdd
} else {
# Multiple matches found - show suggestions
Write-Host "🔍 Multiple applications found matching '$app':" -ForegroundColor Yellow
Write-Host " Please specify which one you want to exclude:" -ForegroundColor DarkGray
Write-Host ""
for ($i = 0; $i -lt $suggestions.Count; $i++) {
$suggestion = $suggestions[$i]
Write-Host " [$($i + 1)] " -NoNewline -ForegroundColor Cyan
Write-Host "$($suggestion.Name)" -NoNewline -ForegroundColor White
Write-Host " (" -NoNewline -ForegroundColor DarkGray
Write-Host "$($suggestion.Id)" -NoNewline -ForegroundColor Yellow
Write-Host ")" -ForegroundColor DarkGray
}
Write-Host ""
Write-Host " 💡 To exclude a specific app, use:" -ForegroundColor DarkGray
Write-Host " .\winget-update.ps1 -ape `"$($suggestions[0].Id)`"" -ForegroundColor Green
Write-Host ""
}
}
# Add valid apps to the list
if ($validAppsToAdd.Count -gt 0) {
$allApps = @($currentList) + @($validAppsToAdd)
$allApps | Where-Object { $_.Trim() -ne "" } | Set-Content $PersistentExcludeFile
Write-Host "✅ Successfully added to persistent exclude list:" -ForegroundColor Green
foreach ($app in $validAppsToAdd) {
Write-Host " • $app" -ForegroundColor DarkGray
}
}
}
# Function to find matches in the persistent exclude list
function Find-ExcludeListMatches {
param(
[string]$SearchTerm,
[array]$ExcludeList,
[array]$InstalledApps
)
$matches = @()
# Exact match in exclude list
$exactMatch = $ExcludeList | Where-Object { $_ -eq $SearchTerm }
if ($exactMatch) {
return @($exactMatch)
}
# Find the app in installed apps to get both name and ID
$installedApp = $InstalledApps | Where-Object { $_.Name -eq $SearchTerm -or $_.Id -eq $SearchTerm }
if ($installedApp) {
# Check if the ID is in the exclude list
$idMatch = $ExcludeList | Where-Object { $_ -eq $installedApp.Id }
if ($idMatch) {
return @($idMatch)
}
# Check if the name is in the exclude list
$nameMatch = $ExcludeList | Where-Object { $_ -eq $installedApp.Name }
if ($nameMatch) {
return @($nameMatch)
}
}
# Partial matches in exclude list (case insensitive)
$partialMatches = $ExcludeList | Where-Object { $_ -like "*$SearchTerm*" }
$matches += $partialMatches
# Find apps in installed list that match the search term and check if their IDs are in exclude list
$installedMatches = $InstalledApps | Where-Object { $_.Name -like "*$SearchTerm*" -or $_.Id -like "*$SearchTerm*" }
foreach ($installedMatch in $installedMatches) {
$excludeMatch = $ExcludeList | Where-Object { $_ -eq $installedMatch.Id -or $_ -eq $installedMatch.Name }
if ($excludeMatch) {
$matches += $excludeMatch
}
}
# Remove duplicates
$uniqueMatches = @()
foreach ($match in $matches) {
if ($uniqueMatches -notcontains $match) {
$uniqueMatches += $match
}
}
return $uniqueMatches | Select-Object -First 10
}
# Enhanced function to remove applications from the persistent exclude list with smart matching
function Remove-PersistentExcludeApps {
param(
[string[]]$Apps
)
if (-not $Apps -or $Apps.Count -eq 0) {
Write-Host "❌ No applications specified to remove from the persistent exclude list." -ForegroundColor Red
return
}
Write-Host "🔍 Analyzing exclude list and installed applications..." -ForegroundColor Cyan
$currentList = @(Get-PersistentExcludeList)
$installedApps = Get-InstalledApplications
$validAppsToRemove = @()
foreach ($app in $Apps) {
# Find matches for this app in the exclude list
$matches = @(Find-ExcludeListMatches -SearchTerm $app -ExcludeList $currentList -InstalledApps $installedApps)
if ($matches.Count -eq 0) {
Write-Host "❌ No application matching '$app' found in the persistent exclude list." -ForegroundColor Red
# Show what's currently in the exclude list for reference
if ($currentList.Count -gt 0) {
Write-Host " 📋 Current exclude list contains:" -ForegroundColor DarkGray
foreach ($excludedApp in $currentList) {
# Try to find the friendly name for this ID
$friendlyApp = $installedApps | Where-Object { $_.Id -eq $excludedApp }
if ($friendlyApp) {
Write-Host " • $($friendlyApp.Name) ($excludedApp)" -ForegroundColor DarkGray
} else {
Write-Host " • $excludedApp" -ForegroundColor DarkGray
}
}
}
continue
}
if ($matches.Count -eq 1) {
# Exact match found
$appToRemove = $matches[0]
# Find friendly name if possible
$friendlyApp = $installedApps | Where-Object { $_.Id -eq $appToRemove -or $_.Name -eq $appToRemove }
Write-Host "✅ Found match for '$app' in exclude list:" -ForegroundColor Green
if ($friendlyApp) {
Write-Host " 📦 Name: $($friendlyApp.Name)" -ForegroundColor White
Write-Host " 🆔 ID: $($friendlyApp.Id)" -ForegroundColor Cyan
} else {
Write-Host " 🆔 Entry: $appToRemove" -ForegroundColor Cyan
}
Write-Host " ➖ Removing from exclude list..." -ForegroundColor DarkGray
$validAppsToRemove += $appToRemove
} else {
# Multiple matches found - show options
Write-Host "🔍 Multiple entries found in exclude list matching '$app':" -ForegroundColor Yellow
Write-Host " Please specify which one you want to remove:" -ForegroundColor DarkGray
Write-Host ""
for ($i = 0; $i -lt $matches.Count; $i++) {
$match = $matches[$i]
$friendlyApp = $installedApps | Where-Object { $_.Id -eq $match -or $_.Name -eq $match }
Write-Host " [$($i + 1)] " -NoNewline -ForegroundColor Cyan
if ($friendlyApp) {
Write-Host "$($friendlyApp.Name)" -NoNewline -ForegroundColor White
Write-Host " (" -NoNewline -ForegroundColor DarkGray
Write-Host "$match" -NoNewline -ForegroundColor Yellow
Write-Host ")" -ForegroundColor DarkGray
} else {
Write-Host "$match" -ForegroundColor Yellow
}
}
Write-Host ""
Write-Host " 💡 To remove a specific app, use:" -ForegroundColor DarkGray
Write-Host " .\winget-update.ps1 -rpe `"$($matches[0])`"" -ForegroundColor Green
Write-Host ""
}
}
# Remove valid apps from the list
if ($validAppsToRemove.Count -gt 0) {
$newList = @($currentList | Where-Object { $validAppsToRemove -notcontains $_ })
$newList | Where-Object { $_.Trim() -ne "" } | Set-Content $PersistentExcludeFile
Write-Host "✅ Successfully removed from persistent exclude list:" -ForegroundColor Green
foreach ($app in $validAppsToRemove) {
# Try to show friendly name
$friendlyApp = $installedApps | Where-Object { $_.Id -eq $app -or $_.Name -eq $app }
if ($friendlyApp) {
Write-Host " • $($friendlyApp.Name) ($app)" -ForegroundColor DarkGray
} else {
Write-Host " • $app" -ForegroundColor DarkGray
}
}
}
}
# Add new persistent exclude apps if specified
if ($AddPersistentExcludeApps) {
Add-PersistentExcludeApps -Apps $AddPersistentExcludeApps
exit
}
# Remove persistent exclude apps if specified
if ($RemovePersistentExcludeApps) {
Remove-PersistentExcludeApps -Apps $RemovePersistentExcludeApps
exit
}
# Retrieve the current persistent exclude list and ensure it's an array
$CurrentPersistentExcludeApps = @(Get-PersistentExcludeList)
# Function to escape special regex characters
function Escape-SpecialCharacters {
param(
[string]$String
)
return [regex]::Escape($String)
}
# Function to get the list of available updates from winget
function Get-WingetUpdates {
Write-Host "🔍 Scanning for available updates..." -ForegroundColor Cyan
try {
# Execute winget with enhanced error handling
$wingetOutput = & winget upgrade --include-unknown 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Winget command failed with exit code: $LASTEXITCODE" -ForegroundColor Red
return @()
}
$lines = $wingetOutput -split "`r`n"
$updates = @()
$headerFound = $false
$startProcessing = $false
foreach ($line in $lines) {
if ($line -match "following packages have|explicit targeting") {
continue
}
if ($line -match "Name\s+Id\s+Version\s+Available\s+Source") {
$headerFound = $true
continue
}
# Wait for a line after the header before starting
if ($headerFound -and $line -match "^-+") {
$startProcessing = $true
continue
}
if ($startProcessing -and $line.Trim() -ne "" -and $line -match "[a-zA-Z0-9]") {
# Use precise regex to capture columns
if ($line -match "^([^│]+?)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)$") {
$name = $matches[1].Trim()
$id = $matches[2].Trim()
$version = $matches[3].Trim()
$available = $matches[4].Trim()
$source = $matches[5].Trim()
# Verify it's a valid line
if ($id -ne "Id" -and $version -ne "Version" -and -not ($name -match "following packages|explicit targeting")) {
$updateInfo = [PSCustomObject]@{
Name = $name
Id = $id
Version = $version
Available = $available
Source = $source
Priority = Get-UpdatePriority -Id $id
Category = Get-PackageCategory -Id $id
SecurityUpdate = Test-SecurityUpdate -Id $id
}
$updates += $updateInfo
}
}
}
}
# Ensure $updates is always an array and remove duplicates
$updates = @($updates)
Write-Host "DEBUG: Raw updates count: $($updates.Count)" -ForegroundColor Magenta
$updates | Where-Object { $_.Name -match "v2ray|2dust" -or $_.Id -match "v2ray|2dust" } | ForEach-Object {
Write-Host "DEBUG: Found v2rayN: $($_.Name) ($($_.Id))" -ForegroundColor Magenta
}
$uniqueUpdates = @($updates | Sort-Object Id -Unique | Sort-Object Priority, Name)
Write-Host "✅ Found $($uniqueUpdates.Count) available updates" -ForegroundColor Green
return $uniqueUpdates
} catch {
Write-Host "❌ Error scanning for updates: $($_.Exception.Message)" -ForegroundColor Red
return @()
}
}
# Function to determine update priority
function Get-UpdatePriority {
param([string]$Id)
# Define priority categories (1 = highest, 3 = lowest)
# High Priority: Critical development tools, security software, system utilities
$highPriority = @(
# Development Tools
"Microsoft.WindowsTerminal", "Microsoft.PowerShell", "Microsoft.VisualStudioCode",
"Microsoft.VisualStudio.2022.Community", "Microsoft.VisualStudio.2022.Professional", "Microsoft.VisualStudio.2022.Enterprise",
"Microsoft.VisualStudio.2022.BuildTools", "Git.Git", "GitHub.GitHubDesktop", "GitKraken.GitKraken",
"JetBrains.IntelliJIDEA.Ultimate", "JetBrains.IntelliJIDEA.Community", "JetBrains.PyCharm.Professional", "JetBrains.PyCharm.Community",
"JetBrains.WebStorm", "JetBrains.PhpStorm", "JetBrains.CLion", "JetBrains.DataGrip", "JetBrains.Rider",
"Docker.DockerDesktop", "Kubernetes.kubectl", "Microsoft.AzureCLI", "Amazon.AWSCLI", "Google.CloudSDK",
# Security & System
"Microsoft.WindowsDefender", "Malwarebytes.Malwarebytes", "ESET.EndpointSecurity", "Bitdefender.Bitdefender",
"Microsoft.Sysinternals.ProcessExplorer", "Microsoft.Sysinternals.ProcessMonitor", "Microsoft.Sysinternals.Autoruns",
# Critical Runtimes
"Microsoft.DotNet.Runtime.6", "Microsoft.DotNet.Runtime.7", "Microsoft.DotNet.Runtime.8",
"Microsoft.VCRedist.2015+.x64", "Microsoft.VCRedist.2015+.x86", "Oracle.JavaRuntimeEnvironment",
"Python.Python.3.11", "Python.Python.3.12", "NodeJS.NodeJS"
)
# Medium Priority: Popular applications, browsers, productivity tools
$mediumPriority = @(
# Browsers
"Google.Chrome", "Mozilla.Firefox", "Microsoft.Edge", "Opera.Opera", "BraveSoftware.BraveBrowser",
"Vivaldi.Vivaldi", "Tor.TorBrowser",
# Productivity & Office
"Microsoft.Office", "Microsoft.Teams", "Zoom.Zoom", "Slack.Slack", "Discord.Discord",
"Notion.Notion", "Obsidian.Obsidian", "Evernote.Evernote", "Dropbox.Dropbox", "Google.Drive",
"Adobe.Acrobat.Reader.64-bit", "SumatraPDF.SumatraPDF", "Foxit.FoxitReader",
# Media & Graphics
"Adobe.Photoshop", "Adobe.Illustrator", "Adobe.Premiere", "Adobe.AfterEffects",
"GIMP.GIMP", "Inkscape.Inkscape", "Blender.Blender", "OBSProject.OBSStudio",
"VLC.VLC", "MPC-HC.MPC-HC", "Spotify.Spotify", "Audacity.Audacity",
# Utilities
"7zip.7zip", "WinRAR.WinRAR", "PeaZip.PeaZip", "Notepad++.Notepad++", "Sublime.SublimeText.4",
"Microsoft.PowerToys", "Sysinternals.ProcessExplorer", "WiresharkFoundation.Wireshark",
# Cloud & Sync
"Microsoft.OneDrive", "Google.BackupAndSync", "Amazon.Kindle", "Evernote.Evernote"
)
if ($Id -in $highPriority) { return 1 }
if ($Id -in $mediumPriority) { return 2 }
# Additional pattern-based priorities
if ($Id -match "Microsoft\.(VisualStudio|DotNet|PowerShell|WindowsTerminal)") { return 1 }
if ($Id -match "JetBrains\.|Docker\.|Kubernetes\.|Git\.") { return 1 }
if ($Id -match "Microsoft\.|Google\.|Adobe\.|Mozilla\.") { return 2 }
if ($Id -match "Antivirus|Security|Defender") { return 1 }
return 3
}
# Function to categorize packages
function Get-PackageCategory {
param([string]$Id)