Skip to content

Commit b2db4f7

Browse files
committed
Add Windows US House Microsoft/Apple software lifecycle script
1 parent cf41d27 commit b2db4f7

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(Mandatory=$true)]
4+
[ValidateSet('install','update','remove','status','list')]
5+
[string]$Action,
6+
7+
[Parameter(Mandatory=$true)]
8+
[ValidateSet('microsoft','apple')]
9+
[string]$Vendor,
10+
11+
[string]$Package,
12+
[switch]$AllUsers
13+
)
14+
15+
Set-StrictMode -Version Latest
16+
$ErrorActionPreference = 'Stop'
17+
18+
function Assert-Winget {
19+
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
20+
throw 'winget is required for Windows package operations.'
21+
}
22+
}
23+
24+
function Invoke-Winget([string[]]$Args) {
25+
Assert-Winget
26+
& winget @Args
27+
if ($LASTEXITCODE -ne 0) { throw "winget failed with exit code $LASTEXITCODE" }
28+
}
29+
30+
$ids = @{
31+
microsoft = @{
32+
'edge' = 'Microsoft.Edge'
33+
'vscode' = 'Microsoft.VisualStudioCode'
34+
'powershell' = 'Microsoft.PowerShell'
35+
'dotnet' = 'Microsoft.DotNet.SDK.8'
36+
'git' = 'Git.Git'
37+
}
38+
apple = @{
39+
'icloud' = 'Apple.iCloud'
40+
'applemusic' = 'Apple.AppleMusic'
41+
'devices' = 'Apple.AppleDevices'
42+
}
43+
}
44+
45+
if ($Action -eq 'list') {
46+
$ids[$Vendor].GetEnumerator() | Sort-Object Name | Format-Table -AutoSize
47+
exit 0
48+
}
49+
50+
if (-not $Package) {
51+
throw 'Specify -Package, or use -Action list to view supported package aliases.'
52+
}
53+
54+
if (-not $ids[$Vendor].ContainsKey($Package)) {
55+
throw "Unsupported $Vendor package alias '$Package'. Use -Action list."
56+
}
57+
58+
$id = $ids[$Vendor][$Package]
59+
$common = @('--id', $id, '--exact', '--source', 'winget')
60+
if ($AllUsers) { $common += '--scope'; $common += 'machine' }
61+
62+
switch ($Action) {
63+
'install' { Invoke-Winget (@('install') + $common + @('--accept-package-agreements','--accept-source-agreements')) }
64+
'update' { Invoke-Winget (@('upgrade') + $common + @('--accept-package-agreements','--accept-source-agreements')) }
65+
'remove' { Invoke-Winget (@('uninstall') + $common) }
66+
'status' { Invoke-Winget (@('list') + $common) }
67+
}

0 commit comments

Comments
 (0)