Skip to content

Commit 4dd3c5e

Browse files
committed
winget upgrade dsc file
1 parent 2040b96 commit 4dd3c5e

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
2+
#
3+
# Common Configuration Sample for .NET Engineers
4+
# =================================
5+
#
6+
# Purpose:
7+
# This DSC configuration sets up a standard development environment with:
8+
# - Development storage using Dev Drive
9+
# - Source control tools (Git, GitHub CLI)
10+
# - Development runtimes (.NET 9 SDK and Runtime)
11+
# - Development tools (VS Code, Node.js)
12+
#
13+
# Prerequisites:
14+
# - Windows 10/11 with admin privileges
15+
# - Internet connectivity for package downloads
16+
#
17+
# Maintainers: DevExp Team
18+
19+
properties:
20+
configurationVersion: "0.2.0"
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

0 commit comments

Comments
 (0)