|
19 | 19 | properties: |
20 | 20 | configurationVersion: "0.2.0" |
21 | 21 | resources: |
22 | | - - resource: PSDscResources/Script |
23 | | - id: Winget-Upgrade-Packages |
24 | | - directives: |
25 | | - description: Upgrade all Microsoft Store apps using winget |
26 | | - securityContext: elevated # Requires admin rights to install apps |
27 | | - settings: |
28 | | - SetScript: | |
29 | | - $ErrorActionPreference = 'Stop' |
30 | | - $ProgressPreference = 'SilentlyContinue' |
31 | | - Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force | Out-Null |
32 | | -
|
33 | | - $scriptUrl = 'https://raw.githubusercontent.com/Evilazaro/DevExp-DevBox/main/.configuration/devcenter/workloads/winget-update.ps1' |
34 | | - $downloadDir = Join-Path $env:TEMP 'DevExp-DevBox-Setup' |
35 | | - $localScript = Join-Path $downloadDir 'winget-update.ps1' |
36 | | -
|
37 | | - # Ensure TLS 1.2 for older hosts |
38 | | - try { |
39 | | - [System.Net.ServicePointManager]::SecurityProtocol = ` |
40 | | - [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12 |
41 | | - } catch { } |
42 | | -
|
43 | | - # Create temp folder if needed |
44 | | - if (-not (Test-Path -LiteralPath $downloadDir)) { |
45 | | - New-Item -ItemType Directory -Path $downloadDir -Force | Out-Null |
46 | | - } |
47 | | -
|
48 | | - # Download script quietly (retry up to 3 times) |
49 | | - $maxAttempts = 3 |
50 | | - for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) { |
51 | | - try { |
52 | | - Invoke-WebRequest -Uri $scriptUrl -OutFile $localScript -UseBasicParsing -TimeoutSec 60 -ErrorAction Stop |
53 | | - break |
54 | | - } catch { |
55 | | - if ($attempt -eq $maxAttempts) { |
56 | | - Write-Error "Failed to download script after $maxAttempts attempts. $_" |
57 | | - exit 1 |
58 | | - } |
59 | | - Start-Sleep -Seconds ([int][Math]::Pow(2, $attempt)) |
60 | | - } |
61 | | - } |
62 | | -
|
63 | | - # Validate and unblock |
64 | | - if (-not (Test-Path -LiteralPath $localScript) -or (Get-Item -LiteralPath $localScript).Length -le 0) { |
65 | | - Write-Error "Downloaded script is missing or empty: $localScript" |
66 | | - exit 1 |
67 | | - } |
68 | | - try { Unblock-File -LiteralPath $localScript } catch { } |
69 | | -
|
70 | | - # Run the script in a separate quiet PowerShell process |
71 | | - Start-Process powershell.exe -ArgumentList @( |
72 | | - '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $localScript |
73 | | - ) -WindowStyle Hidden -Wait |
74 | | -
|
75 | | - GetScript: return $false |
76 | | - TestScript: return $false |
77 | | - |
78 | 22 | #---------------------------------------------- |
79 | 23 | # Storage Configuration |
80 | 24 | #---------------------------------------------- |
|
0 commit comments