From b7f02ac0362e3c6fc34b1d7424add1b2110dc701 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sat, 28 Jun 2025 20:12:57 -0400 Subject: [PATCH] Update StackMonkey.ps1 --- StackMonkey.ps1 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index 3c00dac..442b915 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -91,6 +91,41 @@ [Parameter(ParameterSetName='Datto')][switch] $SaveCopy ) + #region — guarantee NuGet provider is present without prompting + +# ─── Top of script ─── +Import-Module PackageManagement -Force -ErrorAction SilentlyContinue +Import-Module PowerShellGet -Force -ErrorAction SilentlyContinue + +# ─── ensure TLS 1.2 + no prompts ─── +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$ProgressPreference = 'SilentlyContinue' +$ConfirmPreference = 'None' + +# if NuGet isn’t already available, install it non-interactively + +if (-not (Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue)) { + Install-PackageProvider ` + -Name NuGet ` + -MinimumVersion 2.8.5.201 ` + -Force ` + -Confirm:$false +} + +# import it so Register-PSRepository / Install-Module won’t prompt +Import-PackageProvider -Name NuGet -Force -ErrorAction SilentlyContinue + +# ensure PSGallery is trusted (so you don’t get “untrusted repository” prompt +if ((Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue).InstallationPolicy -ne 'Trusted') { + Set-PSRepository ` + -Name PSGallery ` + -InstallationPolicy Trusted ` + -ErrorAction SilentlyContinue +} + +#endregion + + # ───────────────────────────────────────────────────────────────────────── # 2) GLOBAL SETTINGS & HELPERS # ─────────────────────────────────────────────────────────────────────────