-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_once_15_install-module.ps1.tmpl
More file actions
35 lines (27 loc) · 1.12 KB
/
run_once_15_install-module.ps1.tmpl
File metadata and controls
35 lines (27 loc) · 1.12 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
{{ if eq .chezmoi.os "windows" -}}
{{ if ge (atoi .chezmoi.windowsVersion.currentBuild) 17763 }} # don't run if older
# Ensure the module is installed and imported
if (-not (Get-Module -ListAvailable -Name Microsoft.WinGet.Client)) {
try {
# Set TLS 1.2 to avoid hangs on older systems
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Trust PSGallery if needed
if (-not (Get-PSRepository | Where-Object { $_.Name -eq "PSGallery" -and $_.InstallationPolicy -eq "Trusted" })) {
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
}
# Install NuGet if needed
if (-not (Get-PackageProvider -ListAvailable -Name NuGet)) {
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
}
# Install WinGet.Client if needed
if (-not (Get-Module -ListAvailable -Name Microsoft.WinGet.Client)) {
Install-Module -Name Microsoft.WinGet.Client -Scope CurrentUser -Force -Confirm:$false
}
} catch {
Write-Error "Failed to install Microsoft.WinGet.Client: $_"
}
}
# Import it if needed
Import-Module Microsoft.WinGet.Client -ErrorAction SilentlyContinue
{{ end }}
{{ end }}