-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwpi_auto.ps1
More file actions
91 lines (77 loc) · 2.45 KB
/
Copy pathwpi_auto.ps1
File metadata and controls
91 lines (77 loc) · 2.45 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
$Pkgs = @(
"Anthropic.Claude",
"AnyDesk.AnyDesk",
"CharlesMilette.TranslucentTB",
"Cloudflare.Warp",
"Discord.Discord",
"Google.Chrome.EXE",
"Oracle.JavaRuntimeEnvironment",
"qBittorrent.qBittorrent",
"RARLab.WinRAR",
"Valve.Steam",
"VideoLAN.VLC",
"Logitech.GHUB",
"Logitech.OptionsPlus",
"Nvidia.NvidiaApp",
"Kingston.SSDManager",
"CPUID.CPU-Z.ROG",
"TechPowerUp.GPU-Z",
"RiotGames.LeagueOfLegends.BR",
"Blitz.Blitz",
"TeamViewer.TeamViewer",
"REALiX.HWiNFO",
"OCBase.OCCT.Personal",
"Maxon.CinebenchR23"
)
$RootDir = Join-Path -Path $env:UserProfile -ChildPath "WPI"
$DownloadDir = Join-Path -Path $RootDir -ChildPath "downloads"
$OutputLog = Join-Path -Path $RootDir -ChildPath "output.log"
if (-not (Test-Path $RootDir)) { New-Item -ItemType Directory -Path $RootDir | Out-Null }
if (-not (Test-Path $DownloadDir)) { New-Item -ItemType Directory -Path $DownloadDir | Out-Null }
# Functions
function Retry-Command {
param (
[ScriptBlock]$Command,
[int]$MaxRetries = 3,
[int]$RetryDelay = 5
)
$attempts = 0
$success = $false
while (-not $success -and $attempts -lt $MaxRetries) {
try {
& $Command
$success = $true
}
catch {
Write-Warning "Attempt $($attempts + 1) failed. Error: $($_.Exception.Message)"
Start-Sleep -Seconds $RetryDelay
$attempts++
}
}
if (-not $success) {
throw "Command failed after $MaxRetries attempts."
}
}
function Add-WingetPkgs {
foreach ($Pkg in $Pkgs) {
try {
$installed = winget list $Pkg --accept-source-agreements
if ($installed -match ([regex]::Escape($Pkg))) {
Write-Warning "$Pkg is already installed."
}
else {
Retry-Command -Command { winget install --exact --id $Pkg --silent --accept-package-agreements --accept-source-agreements --source winget }
if ($?) { Write-Host "Package $Pkg installed successfully." -ForegroundColor Green }
}
}
catch {
Write-Warning "Failed to install package: $Pkg. Error: $($_.Exception.Message)"
}
}
Write-Host "All packages processed."
}
# Execution
Start-Transcript -Path $OutputLog
Add-WingetPkgs
if (Test-Path $DownloadDir) { Remove-Item -Path $DownloadDir -Recurse -Force | Out-Null }
Stop-Transcript