From a3e03c7c59fd8484f610f941ea9900afe7929fda Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:26:42 +0000 Subject: [PATCH 01/30] =?UTF-8?q?=E2=9C=A8=20feat(function):=20update=20Gi?= =?UTF-8?q?tHub=20CLI=20tools=20in=20Update-AllTheThings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 239 ++++++++++++++---- Scripts/Update-AllTheThings_ScriptInfo.ps1 | 4 +- docs/Update-AllTheThings.md | 3 +- .../Public/Update-AllTheThings.ps1 | 50 +++- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 16 ++ 5 files changed, 253 insertions(+), 59 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index f0992911..a3d07934 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -1,6 +1,6 @@ <#PSScriptInfo -.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, and packages (apt, brew, Chocolatey, winget). -.VERSION 0.5.8 +.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). +.VERSION 0.5.10 .GUID 3a1a1ec9-0ef6-4f84-963d-be1505dab6a8 .AUTHOR Sam Erde .COPYRIGHT (c) 2024 Sam Erde. All rights reserved. @@ -23,16 +23,81 @@ function Test-IsElevated { .OUTPUTS Boolean #> - [CmdletBinding(HelpUri = 'https://day3bits.com/PSPreworkout')] + [CmdletBinding(HelpUri = 'https://day3bits.com/PSPreworkout/Test-IsElevated')] [Alias('isadmin', 'isroot')] + [OutputType([bool])] param () + # Send non-identifying usage statistics to PostHog. + Write-PSPreworkoutTelemetry -EventName $MyInvocation.MyCommand.Name -ParameterNamesOnly $MyInvocation.BoundParameters.Keys + if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) { $CurrentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent()) return $CurrentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } else { - # Must be Linux or OSX, so use the id util. Root has userid of 0. - return 0 -eq (id -u) + # Unix-like systems (Linux, macOS, etc.) + # Method 1: Try id command with error handling + try { + $userId = & id -u 2>$null + if ($LASTEXITCODE -eq 0 -and $null -ne $userId) { + return 0 -eq [int]$userId + } + } catch { + Write-Debug "id command failed: $($_.Exception.Message)" + } + + # Method 2: Check username via .NET + try { + if ([System.Environment]::UserName -eq 'root') { + return $true + } + } catch { + Write-Debug ".NET username check failed: $($_.Exception.Message)" + } + + # Method 3: Check for macOS admin group membership + try { + # Check if we're on macOS and if user is in admin or wheel groups + if ($IsMacOS -or (Get-Command 'sw_vers' -ErrorAction SilentlyContinue)) { + # Method 3a: Use groups command to check admin group membership + $groups = & Get-Groups 2>$null + if ($LASTEXITCODE -eq 0 -and $groups) { + $groupList = $groups -split '\s+' + if ($groupList -contains 'admin' -or $groupList -contains 'wheel') { + return $true + } + } + + # Method 3b: Use id command to check group IDs + $groupIds = & id -G 2>$null + if ($LASTEXITCODE -eq 0 -and $groupIds) { + $gidList = $groupIds -split '\s+' | ForEach-Object { [int]$_ } + if ($gidList -contains 80 -or $gidList -contains 0) { + # 80=admin, 0=wheel + return $true + } + } + } + } catch { + Write-Debug "macOS admin group check failed: $($_.Exception.Message)" + } + + # Method 4: Check effective user ID via /proc (Linux-specific) + try { + if (Test-Path '/proc/self/status') { + $statusContent = Get-Content '/proc/self/status' -ErrorAction SilentlyContinue + $uidLine = $statusContent | Where-Object { $_ -match '^Uid:' } + if ($uidLine -and $uidLine -match '\s+(\d+)\s+') { + return 0 -eq [int]$matches[1] + } + } + } catch { + Write-Debug "/proc status check failed: $($_.Exception.Message)" + } + + # All methods failed + Write-Warning 'Unable to determine elevation status on this Unix-like system. All detection methods failed.' + return $false } } function Update-AllTheThings { @@ -41,7 +106,7 @@ function Update-AllTheThings { Update all the things! .DESCRIPTION - A script to automatically update all PowerShell modules, PowerShell Help, and packages (apt, brew, Chocolatey, winget). + A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). .PARAMETER SkipModules Skip the step that updates PowerShell modules. @@ -70,10 +135,17 @@ function Update-AllTheThings { Update-AllTheThings -AcceptPrompts Updates all of the things and automatically accepts Linux package upgrade prompts. + + .NOTES + Author: Sam Erde + Version: 0.5.10 #> - [CmdletBinding(SupportsShouldProcess)] - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', 'Update-AllTheThings', Justification = 'This is what we do.')] + [CmdletBinding( + SupportsShouldProcess, + HelpUri = 'https://day3bits.com/PSPreworkout/Update-AllTheThings' + )] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'This is what we do.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Interactive Use')] [Alias('uatt')] param ( @@ -110,6 +182,9 @@ function Update-AllTheThings { ) begin { + # Send non-identifying usage statistics to PostHog. + Write-PSPreworkoutTelemetry -EventName $MyInvocation.MyCommand.Name -ParameterNamesOnly $MyInvocation.BoundParameters.Keys + # Spacing to get host output from script, winget, and choco all below the progress bar. $Banner = @" __ __ __ __ ___ ____ @@ -120,7 +195,7 @@ function Update-AllTheThings { /_ __/ / ___ /_ __/ / (_)__ ___ ____ / / / _ \/ -_) / / / _ \/ / _ \/ _ `(_-< /_/ /_//_/\__/ /_/ /_//_/_/_//_/\_, /___/ - /___/ 0.5.9 + /___/ 0.5.10 "@ Write-Host $Banner @@ -128,9 +203,13 @@ function Update-AllTheThings { process { Write-Verbose 'Set the PowerShell Gallery as a trusted installation source.' - Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted + if ($PSCmdlet.ShouldProcess('PSGallery', 'Set PowerShellGet repository as trusted')) { + Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted + } if (Get-Command -Name Set-PSResourceRepository -ErrorAction SilentlyContinue) { - Set-PSResourceRepository -Name 'PSGallery' -Trusted + if ($PSCmdlet.ShouldProcess('PSGallery', 'Set PSResourceGet repository as trusted')) { + Set-PSResourceRepository -Name 'PSGallery' -Trusted + } } #region UpdatePowerShell @@ -197,7 +276,9 @@ function Update-AllTheThings { # Finally update the current module try { - Update-Module $module.Name + if ($PSCmdlet.ShouldProcess($module.Name, 'Update PowerShell module')) { + Update-Module $module.Name + } } catch [Microsoft.PowerShell.Commands.WriteErrorException] { # Add a catch for mismatched certificates between module versions. Write-Verbose $_ @@ -207,7 +288,9 @@ function Update-AllTheThings { # ##### Add a section for installed scripts +++++ if (-not $SkipScripts) { Write-Host '[2] Updating PowerShell Scripts' - Update-Script + if ($PSCmdlet.ShouldProcess('Installed PowerShell scripts', 'Update scripts')) { + Update-Script + } } else { Write-Host '[2] Skipping PowerShell Scripts' } @@ -233,10 +316,12 @@ function Update-AllTheThings { if (-not $SkipHelp) { Write-Host '[3] Updating PowerShell Help' # Fixes error with culture ID 127 (Invariant Country), which is not associated with any language - if ((Get-Culture).LCID -eq 127) { - Update-Help -UICulture en-US -ErrorAction SilentlyContinue - } else { - Update-Help -ErrorAction SilentlyContinue + if ($PSCmdlet.ShouldProcess('PowerShell help files', 'Update help')) { + if ((Get-Culture).LCID -eq 127) { + Update-Help -UICulture en-US -ErrorAction SilentlyContinue + } else { + Update-Help -ErrorAction SilentlyContinue + } } } else { Write-Host '[3] Skipping PowerShell Help' @@ -282,7 +367,9 @@ function Update-AllTheThings { } Write-Progress @ProgressParamOuter if (Get-Command winget -ErrorAction SilentlyContinue) { - winget upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all + if ($PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages')) { + winget upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all + } } else { Write-Host '[4] WinGet was not found. Skipping WinGet update.' } @@ -303,35 +390,39 @@ function Update-AllTheThings { if (Get-Command apt -ErrorAction SilentlyContinue) { Write-Host '[5] Updating apt packages.' - if ($NeedsSudo) { - & sudo apt update - if ($AcceptPrompts) { - & sudo apt upgrade -y - } else { - & sudo apt upgrade - } - } else { - & apt update - if ($AcceptPrompts) { - & apt upgrade -y + if ($PSCmdlet.ShouldProcess('apt packages', 'Update and upgrade packages')) { + if ($NeedsSudo) { + & sudo apt update + if ($AcceptPrompts) { + & sudo apt upgrade -y + } else { + & sudo apt upgrade + } } else { - & apt upgrade + & apt update + if ($AcceptPrompts) { + & apt upgrade -y + } else { + & apt upgrade + } } } } if (Get-Command dnf -ErrorAction SilentlyContinue) { Write-Host '[5] Updating dnf packages.' - if ($NeedsSudo) { - if ($AcceptPrompts) { - & sudo dnf update -y + if ($PSCmdlet.ShouldProcess('dnf packages', 'Update packages')) { + if ($NeedsSudo) { + if ($AcceptPrompts) { + & sudo dnf update -y + } else { + & sudo dnf update + } } else { - & sudo dnf update - } - } else { - if ($AcceptPrompts) { - & dnf update -y - } else { - & dnf update + if ($AcceptPrompts) { + & dnf update -y + } else { + & dnf update + } } } } @@ -343,22 +434,66 @@ function Update-AllTheThings { #region UpdateMacOS # Early testing. No progress bar yet. Need to check for admin and different package managers. if ($IsMacOS) { - softwareupdate -l + if ($PSCmdlet.ShouldProcess('macOS software updates', 'List available updates')) { + softwareupdate -l + } if (Get-Command brew -ErrorAction SilentlyContinue) { Write-Host '[6] Updating brew packages.' - brew update - brew upgrade + if ($PSCmdlet.ShouldProcess('Homebrew packages', 'Update and upgrade packages')) { + brew update + brew upgrade + } } } else { Write-Verbose '[6] Not macOS. Skipping section.' } #endregion UpdateMacOS + #region UpdateGitHubCli + if (Get-Command -Name 'gh' -ErrorAction SilentlyContinue) { + Write-Host '[7] Updating GitHub CLI Extensions' + $PercentCompleteOuter = 90 + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = 'Updating GitHub CLI Extensions' + Status = "Progress: $PercentCompleteOuter`% Complete" + PercentComplete = $PercentCompleteOuter + } + Write-Progress @ProgressParamOuter + if ($PSCmdlet.ShouldProcess('GitHub CLI extensions', 'Upgrade all installed extensions')) { + gh extension upgrade --all + } + } else { + Write-Verbose '[7] GitHub CLI was not found. Skipping section.' + } + #endregion UpdateGitHubCli + + #region UpdateCopilotCli + if (Get-Command -Name 'copilot' -ErrorAction SilentlyContinue) { + Write-Host '[8] Updating GitHub Copilot CLI' + $PercentCompleteOuter = 95 + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = 'Updating GitHub Copilot CLI' + Status = "Progress: $PercentCompleteOuter`% Complete" + PercentComplete = $PercentCompleteOuter + } + Write-Progress @ProgressParamOuter + if ($PSCmdlet.ShouldProcess('GitHub Copilot CLI', 'Update installed CLI')) { + copilot update + } + } else { + Write-Verbose '[8] GitHub Copilot CLI was not found. Skipping section.' + } + #endregion UpdateCopilotCli + #region UpdateChocolatey # Upgrade Chocolatey packages. Need to check for admin to avoid errors/warnings. if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey) { # Update the outer progress bar - $PercentCompleteOuter = 90 + $PercentCompleteOuter = 98 $ProgressParamOuter = @{ Id = 0 Activity = 'Update Everything' @@ -367,21 +502,25 @@ function Update-AllTheThings { PercentComplete = $PercentCompleteOuter } Write-Progress @ProgressParamOuter - Write-Host '[7] Updating Chocolatey Packages' + Write-Host '[9] Updating Chocolatey Packages' # Add a function/parameter to run these two feature configuration options, which requires admin to set. if (Test-IsElevated) { # Oops, this depends on PSPreworkout being installed or that function otherwise being available. - choco feature enable -n=allowGlobalConfirmation - choco feature disable --name=showNonElevatedWarnings + if ($PSCmdlet.ShouldProcess('Chocolatey features', 'Enable global confirmation and disable non-elevated warnings')) { + choco feature enable -n=allowGlobalConfirmation + choco feature disable --name=showNonElevatedWarnings + } } else { Write-Verbose "Run once as an administrator to disable Chocolatey's showNonElevatedWarnings." -Verbose } - choco upgrade chocolatey -y --limit-output --accept-license --no-color - choco upgrade all -y --limit-output --accept-license --no-color + if ($PSCmdlet.ShouldProcess('Chocolatey packages', 'Upgrade Chocolatey and all packages')) { + choco upgrade chocolatey -y --limit-output --accept-license --no-color + choco upgrade all -y --limit-output --accept-license --no-color + } # Padding to reset host before updating the progress bar. Write-Host ' ' } else { - Write-Host '[7] Skipping Chocolatey' + Write-Host '[9] Skipping Chocolatey' } #endregion UpdateChocolatey diff --git a/Scripts/Update-AllTheThings_ScriptInfo.ps1 b/Scripts/Update-AllTheThings_ScriptInfo.ps1 index d3d8b0c4..5ffb6481 100644 --- a/Scripts/Update-AllTheThings_ScriptInfo.ps1 +++ b/Scripts/Update-AllTheThings_ScriptInfo.ps1 @@ -1,6 +1,6 @@ <#PSScriptInfo -.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, and packages (apt, brew, Chocolatey, winget). -.VERSION 0.5.8 +.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). +.VERSION 0.5.10 .GUID 3a1a1ec9-0ef6-4f84-963d-be1505dab6a8 .AUTHOR Sam Erde .COPYRIGHT (c) 2024 Sam Erde. All rights reserved. diff --git a/docs/Update-AllTheThings.md b/docs/Update-AllTheThings.md index f12c61cb..7a44b808 100644 --- a/docs/Update-AllTheThings.md +++ b/docs/Update-AllTheThings.md @@ -32,7 +32,7 @@ This cmdlet has the following aliases: ## DESCRIPTION -A script to automatically update all PowerShell modules, PowerShell Help, and packages (apt, brew, Chocolatey, winget). +A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). ## EXAMPLES @@ -241,4 +241,3 @@ Version: 0.5.10 ## RELATED LINKS {{ Fill in the related links here }} - diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 755a798c..b032ecb7 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -4,7 +4,7 @@ function Update-AllTheThings { Update all the things! .DESCRIPTION - A script to automatically update all PowerShell modules, PowerShell Help, and packages (apt, brew, Chocolatey, winget). + A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). .PARAMETER SkipModules Skip the step that updates PowerShell modules. @@ -93,7 +93,7 @@ function Update-AllTheThings { /_ __/ / ___ /_ __/ / (_)__ ___ ____ / / / _ \/ -_) / / / _ \/ / _ \/ _ `(_-< /_/ /_//_/\__/ /_/ /_//_/_/_//_/\_, /___/ - /___/ v0.5.9 + /___/ v0.5.10 "@ Write-Host $Banner @@ -347,11 +347,51 @@ function Update-AllTheThings { } #endregion UpdateMacOS + #region UpdateGitHubCli + if (Get-Command -Name 'gh' -ErrorAction SilentlyContinue) { + Write-Host '[7] Updating GitHub CLI Extensions' + $PercentCompleteOuter = 90 + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = 'Updating GitHub CLI Extensions' + Status = "Progress: $PercentCompleteOuter`% Complete" + PercentComplete = $PercentCompleteOuter + } + Write-Progress @ProgressParamOuter + if ($PSCmdlet.ShouldProcess('GitHub CLI extensions', 'Upgrade all installed extensions')) { + gh extension upgrade --all + } + } else { + Write-Verbose '[7] GitHub CLI was not found. Skipping section.' + } + #endregion UpdateGitHubCli + + #region UpdateCopilotCli + if (Get-Command -Name 'copilot' -ErrorAction SilentlyContinue) { + Write-Host '[8] Updating GitHub Copilot CLI' + $PercentCompleteOuter = 95 + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = 'Updating GitHub Copilot CLI' + Status = "Progress: $PercentCompleteOuter`% Complete" + PercentComplete = $PercentCompleteOuter + } + Write-Progress @ProgressParamOuter + if ($PSCmdlet.ShouldProcess('GitHub Copilot CLI', 'Update installed CLI')) { + copilot update + } + } else { + Write-Verbose '[8] GitHub Copilot CLI was not found. Skipping section.' + } + #endregion UpdateCopilotCli + #region UpdateChocolatey # Upgrade Chocolatey packages. Need to check for admin to avoid errors/warnings. if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey) { # Update the outer progress bar - $PercentCompleteOuter = 90 + $PercentCompleteOuter = 98 $ProgressParamOuter = @{ Id = 0 Activity = 'Update Everything' @@ -360,7 +400,7 @@ function Update-AllTheThings { PercentComplete = $PercentCompleteOuter } Write-Progress @ProgressParamOuter - Write-Host '[7] Updating Chocolatey Packages' + Write-Host '[9] Updating Chocolatey Packages' # Add a function/parameter to run these two feature configuration options, which requires admin to set. if (Test-IsElevated) { # Oops, this depends on PSPreworkout being installed or that function otherwise being available. @@ -378,7 +418,7 @@ function Update-AllTheThings { # Padding to reset host before updating the progress bar. Write-Host ' ' } else { - Write-Host '[7] Skipping Chocolatey' + Write-Host '[9] Skipping Chocolatey' } #endregion UpdateChocolatey diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 2dec51c2..6606a6ba 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -66,6 +66,12 @@ Describe 'Update-AllTheThings' { $Help.Examples.Example.Count | Should -BeGreaterOrEqual 2 } + It 'Should mention GitHub CLI tools in help description' { + $Help = Get-Help Update-AllTheThings + $Help.Description.Text | Should -Match 'GitHub CLI' + $Help.Description.Text | Should -Match 'GitHub Copilot CLI' + } + It 'Should have an example demonstrating AcceptPrompts usage' { $Help = Get-Help Update-AllTheThings -Examples $ExamplesText = $Help.Examples.Example.Code -join ' ' @@ -88,6 +94,16 @@ Describe 'Update-AllTheThings' { $Function = Get-Command Update-AllTheThings $Function.ScriptBlock.Attributes.TypeId.Name | Should -Contain 'SuppressMessageAttribute' } + + It 'Should update installed GitHub CLI extensions when gh is available' { + $Function = Get-Command Update-AllTheThings + $Function.Definition | Should -Match 'gh extension upgrade --all' + } + + It 'Should update GitHub Copilot CLI when copilot is available' { + $Function = Get-Command Update-AllTheThings + $Function.Definition | Should -Match 'copilot update' + } } Context 'Parameter Types' { From 2ff899bfc6097c25031b03039dfff03445b0b3ec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:27:25 +0000 Subject: [PATCH 02/30] =?UTF-8?q?=F0=9F=93=9A=20docs(help):=20align=20Upda?= =?UTF-8?q?te-AllTheThings=20GitHub=20CLI=20help=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 4 ++-- Scripts/Update-AllTheThings_ScriptInfo.ps1 | 2 +- docs/Update-AllTheThings.md | 4 +++- src/PSPreworkout/Public/Update-AllTheThings.ps1 | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index a3d07934..937ea89f 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -1,5 +1,5 @@ <#PSScriptInfo -.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). +.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, winget). .VERSION 0.5.10 .GUID 3a1a1ec9-0ef6-4f84-963d-be1505dab6a8 .AUTHOR Sam Erde @@ -106,7 +106,7 @@ function Update-AllTheThings { Update all the things! .DESCRIPTION - A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). + A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, winget). .PARAMETER SkipModules Skip the step that updates PowerShell modules. diff --git a/Scripts/Update-AllTheThings_ScriptInfo.ps1 b/Scripts/Update-AllTheThings_ScriptInfo.ps1 index 5ffb6481..a62605e5 100644 --- a/Scripts/Update-AllTheThings_ScriptInfo.ps1 +++ b/Scripts/Update-AllTheThings_ScriptInfo.ps1 @@ -1,5 +1,5 @@ <#PSScriptInfo -.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). +.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, winget). .VERSION 0.5.10 .GUID 3a1a1ec9-0ef6-4f84-963d-be1505dab6a8 .AUTHOR Sam Erde diff --git a/docs/Update-AllTheThings.md b/docs/Update-AllTheThings.md index 7a44b808..99728bc7 100644 --- a/docs/Update-AllTheThings.md +++ b/docs/Update-AllTheThings.md @@ -32,7 +32,9 @@ This cmdlet has the following aliases: ## DESCRIPTION -A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). +A script to automatically update all PowerShell modules, PowerShell Help, +GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, +Chocolatey, winget). ## EXAMPLES diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index b032ecb7..c2976b4d 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -4,7 +4,7 @@ function Update-AllTheThings { Update all the things! .DESCRIPTION - A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI tools, and packages (apt, brew, Chocolatey, winget). + A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, winget). .PARAMETER SkipModules Skip the step that updates PowerShell modules. From a47ac598eed5a354e351c8eeae61d75688b2f7fe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:28:39 +0000 Subject: [PATCH 03/30] =?UTF-8?q?=F0=9F=90=9B=20fix(function):=20correct?= =?UTF-8?q?=20Update-AllTheThings=20CLI=20update=20safeguards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 4 +- src/PSPreworkout/Public/Test-IsElevated.ps1 | 2 +- .../Public/Update-AllTheThings.ps1 | 2 +- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 100 ++++++++++++++++++ 4 files changed, 104 insertions(+), 4 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 937ea89f..fd2a9865 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -60,7 +60,7 @@ function Test-IsElevated { # Check if we're on macOS and if user is in admin or wheel groups if ($IsMacOS -or (Get-Command 'sw_vers' -ErrorAction SilentlyContinue)) { # Method 3a: Use groups command to check admin group membership - $groups = & Get-Groups 2>$null + $groups = & groups 2>$null if ($LASTEXITCODE -eq 0 -and $groups) { $groupList = $groups -split '\s+' if ($groupList -contains 'admin' -or $groupList -contains 'wheel') { @@ -345,7 +345,7 @@ function Update-AllTheThings { $Result = $Host.UI.PromptForChoice($Title, $Message, $Options, 1) switch ($Result) { 0 { - continue + Write-Verbose 'Continuing with WinGet package updates.' } 1 { $SkipWinGet = $true diff --git a/src/PSPreworkout/Public/Test-IsElevated.ps1 b/src/PSPreworkout/Public/Test-IsElevated.ps1 index 536933f7..eba3acbf 100644 --- a/src/PSPreworkout/Public/Test-IsElevated.ps1 +++ b/src/PSPreworkout/Public/Test-IsElevated.ps1 @@ -49,7 +49,7 @@ function Test-IsElevated { # Check if we're on macOS and if user is in admin or wheel groups if ($IsMacOS -or (Get-Command 'sw_vers' -ErrorAction SilentlyContinue)) { # Method 3a: Use groups command to check admin group membership - $groups = & Get-Groups 2>$null + $groups = & groups 2>$null if ($LASTEXITCODE -eq 0 -and $groups) { $groupList = $groups -split '\s+' if ($groupList -contains 'admin' -or $groupList -contains 'wheel') { diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index c2976b4d..bf301d8b 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -243,7 +243,7 @@ function Update-AllTheThings { $Result = $Host.UI.PromptForChoice($Title, $Message, $Options, 1) switch ($Result) { 0 { - continue + Write-Verbose 'Continuing with WinGet package updates.' } 1 { $SkipWinGet = $true diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 6606a6ba..5a4a3142 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -2,6 +2,47 @@ BeforeAll { # Import the module or function under test $ModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent $PublicPath = Join-Path -Path $ModulePath -ChildPath 'PSPreworkout\Public' + + function Write-PSPreworkoutTelemetry { + [CmdletBinding()] + param( + [Parameter()] + [string]$EventName, + + [Parameter()] + [string[]]$ParameterNamesOnly + ) + + $EventName, $ParameterNamesOnly | Out-Null + } + + function Test-IsElevated { + [CmdletBinding()] + param() + + return $false + } + + function gh { + [CmdletBinding()] + param( + [Parameter(ValueFromRemainingArguments)] + [string[]]$Arguments + ) + + $Arguments | Out-Null + } + + function copilot { + [CmdletBinding()] + param( + [Parameter(ValueFromRemainingArguments)] + [string[]]$Arguments + ) + + $Arguments | Out-Null + } + . (Join-Path -Path $PublicPath -ChildPath 'Update-AllTheThings.ps1') } @@ -106,6 +147,65 @@ Describe 'Update-AllTheThings' { } } + Context 'GitHub CLI Tool Updates' { + BeforeEach { + Mock Set-PSRepository {} + Mock Write-Host {} + Mock Write-Progress {} + Mock Write-Verbose {} + Mock gh {} + Mock copilot {} + } + + It 'Runs gh extension upgrade when gh is available' { + Mock Get-Command { + param($Name) + + if ($Name -eq 'gh') { + return @{ Name = 'gh' } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet + + Should -Invoke gh -Exactly 1 -ParameterFilter { ($Arguments -join ' ') -eq 'extension upgrade --all' } + } + + It 'Does not run gh extension upgrade when gh is unavailable' { + Mock Get-Command { $null } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet + + Should -Invoke gh -Exactly 0 + } + + It 'Runs copilot update when copilot is available' { + Mock Get-Command { + param($Name) + + if ($Name -eq 'copilot') { + return @{ Name = 'copilot' } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet + + Should -Invoke copilot -Exactly 1 -ParameterFilter { ($Arguments -join ' ') -eq 'update' } + } + + It 'Does not run copilot update when copilot is unavailable' { + Mock Get-Command { $null } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet + + Should -Invoke copilot -Exactly 0 + } + } + Context 'Parameter Types' { It 'Should have all Skip parameters as switch type' { $Function = Get-Command Update-AllTheThings From fcfeaae4b1e3300527f08941fd8c77611aa3bbec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:30:31 +0000 Subject: [PATCH 04/30] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(function):?= =?UTF-8?q?=20tighten=20Update-AllTheThings=20CLI=20update=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 92 +++++++++++------ .../Public/Update-AllTheThings.ps1 | 92 +++++++++++------ src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 99 +++++++++++++++++++ 3 files changed, 221 insertions(+), 62 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index fd2a9865..b28f59d6 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -212,6 +212,48 @@ function Update-AllTheThings { } } + $InvokeOptionalCliUpdate = { + param( + [Parameter(Mandatory)] + [string]$CommandName, + + [Parameter(Mandatory)] + [string]$DisplayName, + + [Parameter(Mandatory)] + [string]$CurrentOperation, + + [Parameter(Mandatory)] + [string]$TargetName, + + [Parameter(Mandatory)] + [string]$ActionName, + + [Parameter(Mandatory)] + [int]$PercentComplete, + + [Parameter(Mandatory)] + [scriptblock]$UpdateCommand + ) + + if (Get-Command -Name $CommandName -ErrorAction SilentlyContinue) { + Write-Host $DisplayName + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = $CurrentOperation + Status = "Progress: $PercentComplete`% Complete" + PercentComplete = $PercentComplete + } + Write-Progress @ProgressParamOuter + if ($PSCmdlet.ShouldProcess($TargetName, $ActionName)) { + & $UpdateCommand + } + } else { + Write-Verbose "$DisplayName was skipped because $CommandName was not found." + } + } + #region UpdatePowerShell # ==================== Update PowerShell Modules ==================== @@ -342,7 +384,11 @@ function Update-AllTheThings { $Title = 'Windows Server OS Found' $Message = "Do you want to run 'winget update' on your server?" - $Result = $Host.UI.PromptForChoice($Title, $Message, $Options, 1) + if (Get-Command -Name 'Get-HostChoice' -ErrorAction SilentlyContinue) { + $Result = Get-HostChoice -Title $Title -Message $Message -Options $Options -DefaultChoice 1 + } else { + $Result = $Host.UI.PromptForChoice($Title, $Message, $Options, 1) + } switch ($Result) { 0 { Write-Verbose 'Continuing with WinGet package updates.' @@ -450,43 +496,27 @@ function Update-AllTheThings { #endregion UpdateMacOS #region UpdateGitHubCli - if (Get-Command -Name 'gh' -ErrorAction SilentlyContinue) { - Write-Host '[7] Updating GitHub CLI Extensions' - $PercentCompleteOuter = 90 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating GitHub CLI Extensions' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - if ($PSCmdlet.ShouldProcess('GitHub CLI extensions', 'Upgrade all installed extensions')) { + & $InvokeOptionalCliUpdate -CommandName 'gh' ` + -DisplayName '[7] Updating GitHub CLI Extensions' ` + -CurrentOperation 'Updating GitHub CLI Extensions' ` + -TargetName 'GitHub CLI extensions' ` + -ActionName 'Upgrade all installed extensions' ` + -PercentComplete 90 ` + -UpdateCommand { gh extension upgrade --all } - } else { - Write-Verbose '[7] GitHub CLI was not found. Skipping section.' - } #endregion UpdateGitHubCli #region UpdateCopilotCli - if (Get-Command -Name 'copilot' -ErrorAction SilentlyContinue) { - Write-Host '[8] Updating GitHub Copilot CLI' - $PercentCompleteOuter = 95 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating GitHub Copilot CLI' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - if ($PSCmdlet.ShouldProcess('GitHub Copilot CLI', 'Update installed CLI')) { + & $InvokeOptionalCliUpdate -CommandName 'copilot' ` + -DisplayName '[8] Updating GitHub Copilot CLI' ` + -CurrentOperation 'Updating GitHub Copilot CLI' ` + -TargetName 'GitHub Copilot CLI' ` + -ActionName 'Update installed CLI' ` + -PercentComplete 95 ` + -UpdateCommand { copilot update } - } else { - Write-Verbose '[8] GitHub Copilot CLI was not found. Skipping section.' - } #endregion UpdateCopilotCli #region UpdateChocolatey diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index bf301d8b..007691c0 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -110,6 +110,48 @@ function Update-AllTheThings { } } + $InvokeOptionalCliUpdate = { + param( + [Parameter(Mandatory)] + [string]$CommandName, + + [Parameter(Mandatory)] + [string]$DisplayName, + + [Parameter(Mandatory)] + [string]$CurrentOperation, + + [Parameter(Mandatory)] + [string]$TargetName, + + [Parameter(Mandatory)] + [string]$ActionName, + + [Parameter(Mandatory)] + [int]$PercentComplete, + + [Parameter(Mandatory)] + [scriptblock]$UpdateCommand + ) + + if (Get-Command -Name $CommandName -ErrorAction SilentlyContinue) { + Write-Host $DisplayName + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = $CurrentOperation + Status = "Progress: $PercentComplete`% Complete" + PercentComplete = $PercentComplete + } + Write-Progress @ProgressParamOuter + if ($PSCmdlet.ShouldProcess($TargetName, $ActionName)) { + & $UpdateCommand + } + } else { + Write-Verbose "$DisplayName was skipped because $CommandName was not found." + } + } + #region UpdatePowerShell # ==================== Update PowerShell Modules ==================== @@ -240,7 +282,11 @@ function Update-AllTheThings { $Title = 'Windows Server OS Found' $Message = "Do you want to run 'winget update' on your server?" - $Result = $Host.UI.PromptForChoice($Title, $Message, $Options, 1) + if (Get-Command -Name 'Get-HostChoice' -ErrorAction SilentlyContinue) { + $Result = Get-HostChoice -Title $Title -Message $Message -Options $Options -DefaultChoice 1 + } else { + $Result = $Host.UI.PromptForChoice($Title, $Message, $Options, 1) + } switch ($Result) { 0 { Write-Verbose 'Continuing with WinGet package updates.' @@ -348,43 +394,27 @@ function Update-AllTheThings { #endregion UpdateMacOS #region UpdateGitHubCli - if (Get-Command -Name 'gh' -ErrorAction SilentlyContinue) { - Write-Host '[7] Updating GitHub CLI Extensions' - $PercentCompleteOuter = 90 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating GitHub CLI Extensions' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - if ($PSCmdlet.ShouldProcess('GitHub CLI extensions', 'Upgrade all installed extensions')) { + & $InvokeOptionalCliUpdate -CommandName 'gh' ` + -DisplayName '[7] Updating GitHub CLI Extensions' ` + -CurrentOperation 'Updating GitHub CLI Extensions' ` + -TargetName 'GitHub CLI extensions' ` + -ActionName 'Upgrade all installed extensions' ` + -PercentComplete 90 ` + -UpdateCommand { gh extension upgrade --all } - } else { - Write-Verbose '[7] GitHub CLI was not found. Skipping section.' - } #endregion UpdateGitHubCli #region UpdateCopilotCli - if (Get-Command -Name 'copilot' -ErrorAction SilentlyContinue) { - Write-Host '[8] Updating GitHub Copilot CLI' - $PercentCompleteOuter = 95 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating GitHub Copilot CLI' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - if ($PSCmdlet.ShouldProcess('GitHub Copilot CLI', 'Update installed CLI')) { + & $InvokeOptionalCliUpdate -CommandName 'copilot' ` + -DisplayName '[8] Updating GitHub Copilot CLI' ` + -CurrentOperation 'Updating GitHub Copilot CLI' ` + -TargetName 'GitHub Copilot CLI' ` + -ActionName 'Update installed CLI' ` + -PercentComplete 95 ` + -UpdateCommand { copilot update } - } else { - Write-Verbose '[8] GitHub Copilot CLI was not found. Skipping section.' - } #endregion UpdateCopilotCli #region UpdateChocolatey diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 5a4a3142..c698c85d 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -2,6 +2,7 @@ BeforeAll { # Import the module or function under test $ModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent $PublicPath = Join-Path -Path $ModulePath -ChildPath 'PSPreworkout\Public' + $script:OriginalIsWindows = $IsWindows function Write-PSPreworkoutTelemetry { [CmdletBinding()] @@ -43,9 +44,54 @@ BeforeAll { $Arguments | Out-Null } + function winget { + [CmdletBinding()] + param( + [Parameter(ValueFromRemainingArguments)] + [string[]]$Arguments + ) + + $Arguments | Out-Null + } + + function Get-HostChoice { + [CmdletBinding()] + param( + [Parameter()] + [string]$Title, + + [Parameter()] + [string]$Message, + + [Parameter()] + [System.Management.Automation.Host.ChoiceDescription[]]$Options, + + [Parameter()] + [int]$DefaultChoice + ) + + $Title, $Message, $Options, $DefaultChoice | Out-Null + return 0 + } + + function Get-CimInstance { + [CmdletBinding()] + param( + [Parameter()] + [string]$ClassName + ) + + $ClassName | Out-Null + return @{ Caption = 'Windows 11' } + } + . (Join-Path -Path $PublicPath -ChildPath 'Update-AllTheThings.ps1') } +AfterAll { + Set-Variable -Name IsWindows -Value $script:OriginalIsWindows -Force +} + Describe 'Update-AllTheThings' { Context 'Parameter Validation' { It 'Should have the correct parameters defined' { @@ -206,6 +252,59 @@ Describe 'Update-AllTheThings' { } } + Context 'Windows Server WinGet Prompt' { + BeforeEach { + Set-Variable -Name IsWindows -Value $true -Force + Mock Set-PSRepository {} + Mock Write-Host {} + Mock Write-Progress {} + Mock Write-Verbose {} + Mock Write-Warning {} + Mock winget {} + Mock Get-CimInstance { @{ Caption = 'Windows Server 2025 Datacenter' } } + } + + AfterEach { + Set-Variable -Name IsWindows -Value $script:OriginalIsWindows -Force + } + + It 'Continues with WinGet updates when the server prompt returns Yes' { + Mock Get-HostChoice { 0 } + Mock Get-Command { + param($Name) + + if ($Name -in @('Get-HostChoice', 'winget')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp + + Should -Invoke winget -Exactly 1 -ParameterFilter { + ($Arguments -join ' ') -eq 'upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all' + } + } + + It 'Skips WinGet updates when the server prompt returns No' { + Mock Get-HostChoice { 1 } + Mock Get-Command { + param($Name) + + if ($Name -in @('Get-HostChoice', 'winget')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp + + Should -Invoke winget -Exactly 0 + } + } + Context 'Parameter Types' { It 'Should have all Skip parameters as switch type' { $Function = Get-Command Update-AllTheThings From 4471b75f148f703da08fa3bb9897aa3f3d84e2de Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:31:24 +0000 Subject: [PATCH 05/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20preserve=20?= =?UTF-8?q?later=20updates=20when=20skipping=20WinGet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 5 ++--- .../Public/Update-AllTheThings.ps1 | 5 ++--- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index b28f59d6..19bf3338 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -374,7 +374,7 @@ function Update-AllTheThings { # >>> Create a section to check OS and client/server OS at the top of the script <<< # if ($IsWindows -or ($PSVersionTable.PSVersion -le [version]'5.1')) { - if ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server') { + if ((-not $SkipWinGet) -and ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' @@ -420,8 +420,7 @@ function Update-AllTheThings { Write-Host '[4] WinGet was not found. Skipping WinGet update.' } } else { - Write-Host '[3] Skipping WinGet' - continue + Write-Host '[4] Skipping WinGet' } } else { Write-Verbose '[4] Not Windows. Skipping WinGet.' diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 007691c0..c3e25922 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -272,7 +272,7 @@ function Update-AllTheThings { # >>> Create a section to check OS and client/server OS at the top of the script <<< # if ($IsWindows -or ($PSVersionTable.PSVersion -le [version]'5.1')) { - if ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server') { + if ((-not $SkipWinGet) -and ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' @@ -318,8 +318,7 @@ function Update-AllTheThings { Write-Host '[4] WinGet was not found. Skipping WinGet update.' } } else { - Write-Host '[3] Skipping WinGet' - continue + Write-Host '[4] Skipping WinGet' } } else { Write-Verbose '[4] Not Windows. Skipping WinGet.' diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index c698c85d..7bd37aa4 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -303,6 +303,26 @@ Describe 'Update-AllTheThings' { Should -Invoke winget -Exactly 0 } + + It 'Still runs later CLI updates when WinGet is skipped explicitly' { + Mock gh {} + Mock copilot {} + Mock Get-Command { + param($Name) + + if ($Name -in @('gh', 'copilot')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet + + Should -Invoke gh -Exactly 1 -ParameterFilter { ($Arguments -join ' ') -eq 'extension upgrade --all' } + Should -Invoke copilot -Exactly 1 -ParameterFilter { ($Arguments -join ' ') -eq 'update' } + Should -Invoke winget -Exactly 0 + } } Context 'Parameter Types' { From f146b9d2e3d41d2fb8baf0f43b191449af888416 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:32:02 +0000 Subject: [PATCH 06/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20guard=20Win?= =?UTF-8?q?Get=20prompt=20behind=20command=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 12 +++++++++--- src/PSPreworkout/Public/Update-AllTheThings.ps1 | 12 +++++++++--- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 19bf3338..50230ce6 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -373,8 +373,14 @@ function Update-AllTheThings { #region UpdateWinget # >>> Create a section to check OS and client/server OS at the top of the script <<< # if ($IsWindows -or ($PSVersionTable.PSVersion -le [version]'5.1')) { - - if ((-not $SkipWinGet) -and ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server')) { + $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue + + if ( + $WinGetCommand -and + (-not $SkipWinGet) -and + (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) -and + ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server') + ) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' @@ -412,7 +418,7 @@ function Update-AllTheThings { PercentComplete = $PercentCompleteOuter } Write-Progress @ProgressParamOuter - if (Get-Command winget -ErrorAction SilentlyContinue) { + if ($WinGetCommand) { if ($PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages')) { winget upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all } diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index c3e25922..0cbcc25b 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -271,8 +271,14 @@ function Update-AllTheThings { #region UpdateWinget # >>> Create a section to check OS and client/server OS at the top of the script <<< # if ($IsWindows -or ($PSVersionTable.PSVersion -le [version]'5.1')) { - - if ((-not $SkipWinGet) -and ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server')) { + $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue + + if ( + $WinGetCommand -and + (-not $SkipWinGet) -and + (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) -and + ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server') + ) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' @@ -310,7 +316,7 @@ function Update-AllTheThings { PercentComplete = $PercentCompleteOuter } Write-Progress @ProgressParamOuter - if (Get-Command winget -ErrorAction SilentlyContinue) { + if ($WinGetCommand) { if ($PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages')) { winget upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all } diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 7bd37aa4..f023d9be 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -273,7 +273,7 @@ Describe 'Update-AllTheThings' { Mock Get-Command { param($Name) - if ($Name -in @('Get-HostChoice', 'winget')) { + if ($Name -in @('Get-CimInstance', 'Get-HostChoice', 'winget')) { return @{ Name = $Name } } @@ -292,7 +292,7 @@ Describe 'Update-AllTheThings' { Mock Get-Command { param($Name) - if ($Name -in @('Get-HostChoice', 'winget')) { + if ($Name -in @('Get-CimInstance', 'Get-HostChoice', 'winget')) { return @{ Name = $Name } } From 592e3bd44f82cee6892bc19718625a0b613eb65d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:32:59 +0000 Subject: [PATCH 07/30] =?UTF-8?q?=F0=9F=94=92=20security(function):=20keep?= =?UTF-8?q?=20WinGet=20server=20safeguards=20on=20legacy=20hosts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 13 +++++-- .../Public/Update-AllTheThings.ps1 | 13 +++++-- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 34 +++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 50230ce6..cb9ae400 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -147,6 +147,7 @@ function Update-AllTheThings { )] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'This is what we do.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Interactive Use')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWMICmdlet', '', Justification = 'Get-WmiObject is used as a fallback when CimCmdlets are unavailable.')] [Alias('uatt')] param ( # Skip the step that updates PowerShell modules @@ -374,12 +375,20 @@ function Update-AllTheThings { # >>> Create a section to check OS and client/server OS at the top of the script <<< # if ($IsWindows -or ($PSVersionTable.PSVersion -le [version]'5.1')) { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue + $WindowsOsCaption = $null + + if ($WinGetCommand -and (-not $SkipWinGet)) { + if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption + } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption + } + } if ( $WinGetCommand -and (-not $SkipWinGet) -and - (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) -and - ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server') + ($WindowsOsCaption -match 'Server') ) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 0cbcc25b..10c250f7 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -45,6 +45,7 @@ function Update-AllTheThings { )] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'This is what we do.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Interactive Use')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWMICmdlet', '', Justification = 'Get-WmiObject is used as a fallback when CimCmdlets are unavailable.')] [Alias('uatt')] param ( # Skip the step that updates PowerShell modules @@ -272,12 +273,20 @@ function Update-AllTheThings { # >>> Create a section to check OS and client/server OS at the top of the script <<< # if ($IsWindows -or ($PSVersionTable.PSVersion -le [version]'5.1')) { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue + $WindowsOsCaption = $null + + if ($WinGetCommand -and (-not $SkipWinGet)) { + if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption + } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption + } + } if ( $WinGetCommand -and (-not $SkipWinGet) -and - (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) -and - ((Get-CimInstance -ClassName CIM_OperatingSystem).Caption -match 'Server') + ($WindowsOsCaption -match 'Server') ) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index f023d9be..6a1aff53 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -85,6 +85,17 @@ BeforeAll { return @{ Caption = 'Windows 11' } } + function Get-WmiObject { + [CmdletBinding()] + param( + [Parameter()] + [string]$Class + ) + + $Class | Out-Null + return @{ Caption = 'Windows 11' } + } + . (Join-Path -Path $PublicPath -ChildPath 'Update-AllTheThings.ps1') } @@ -304,6 +315,29 @@ Describe 'Update-AllTheThings' { Should -Invoke winget -Exactly 0 } + It 'Falls back to WMI for the server prompt when CIM is unavailable' { + Mock Get-HostChoice { 0 } + Mock Get-CimInstance {} + Mock Get-WmiObject { @{ Caption = 'Windows Server 2025 Datacenter' } } + Mock Get-Command { + param($Name) + + if ($Name -in @('Get-HostChoice', 'Get-WmiObject', 'winget')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp + + Should -Invoke Get-CimInstance -Exactly 0 + Should -Invoke Get-WmiObject -Exactly 1 -ParameterFilter { $Class -eq 'Win32_OperatingSystem' } + Should -Invoke winget -Exactly 1 -ParameterFilter { + ($Arguments -join ' ') -eq 'upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all' + } + } + It 'Still runs later CLI updates when WinGet is skipped explicitly' { Mock gh {} Mock copilot {} From 4d280376dba51dee5369354bec192dcf25d102b3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:33:44 +0000 Subject: [PATCH 08/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20avoid=20mis?= =?UTF-8?q?leading=20WinGet=20update=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 24 +++++++++---------- .../Public/Update-AllTheThings.ps1 | 24 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index cb9ae400..859f1a55 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -415,19 +415,19 @@ function Update-AllTheThings { } if (-not $SkipWinGet) { - # Update all winget packages - Write-Host '[4] Updating Winget Packages' - # Update the outer progress bar for winget section - $PercentCompleteOuter = 80 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating Winget Packages' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter if ($WinGetCommand) { + # Update all winget packages + Write-Host '[4] Updating Winget Packages' + # Update the outer progress bar for winget section + $PercentCompleteOuter = 80 + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = 'Updating Winget Packages' + Status = "Progress: $PercentCompleteOuter`% Complete" + PercentComplete = $PercentCompleteOuter + } + Write-Progress @ProgressParamOuter if ($PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages')) { winget upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all } diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 10c250f7..0f164204 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -313,19 +313,19 @@ function Update-AllTheThings { } if (-not $SkipWinGet) { - # Update all winget packages - Write-Host '[4] Updating Winget Packages' - # Update the outer progress bar for winget section - $PercentCompleteOuter = 80 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating Winget Packages' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter if ($WinGetCommand) { + # Update all winget packages + Write-Host '[4] Updating Winget Packages' + # Update the outer progress bar for winget section + $PercentCompleteOuter = 80 + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = 'Updating Winget Packages' + Status = "Progress: $PercentCompleteOuter`% Complete" + PercentComplete = $PercentCompleteOuter + } + Write-Progress @ProgressParamOuter if ($PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages')) { winget upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all } From 9503e4fb09f362e6b45629c5be84383d72323dac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:34:22 +0000 Subject: [PATCH 09/30] =?UTF-8?q?=F0=9F=94=92=20security(cmdlet):=20skip?= =?UTF-8?q?=20WinGet=20when=20server=20checks=20are=20unavailable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 3 +++ .../Public/Update-AllTheThings.ps1 | 3 +++ src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 859f1a55..4956be7a 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -382,6 +382,9 @@ function Update-AllTheThings { $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption + } else { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' + $SkipWinGet = $true } } diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 0f164204..cb60d05b 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -280,6 +280,9 @@ function Update-AllTheThings { $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption + } else { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' + $SkipWinGet = $true } } diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 6a1aff53..5d62b1e9 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -338,6 +338,25 @@ Describe 'Update-AllTheThings' { } } + It 'Skips WinGet when the Windows OS caption cannot be determined' { + Mock Get-Command { + param($Name) + + if ($Name -eq 'winget') { + return @{ Name = 'winget' } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp + + Should -Invoke Write-Warning -Exactly 1 -ParameterFilter { + $Message -match 'Unable to determine the Windows operating system caption' + } + Should -Invoke winget -Exactly 0 + } + It 'Still runs later CLI updates when WinGet is skipped explicitly' { Mock gh {} Mock copilot {} From da8aa284901bd9a2b7abcbe14ec4e30290d07a3b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:35:31 +0000 Subject: [PATCH 10/30] =?UTF-8?q?=F0=9F=94=92=20security(cmdlet):=20gate?= =?UTF-8?q?=20server-side=20CLI=20updates=20behind=20safety=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 88 ++++++++++++------- docs/Update-AllTheThings.md | 2 +- .../Public/Update-AllTheThings.ps1 | 88 ++++++++++++------- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 20 ++++- 4 files changed, 128 insertions(+), 70 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 4956be7a..6836e463 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -255,6 +255,10 @@ function Update-AllTheThings { } } + $SkipGitHubCli = $false + $SkipCopilotCli = $false + $SkipChocolateyUpdates = $false + #region UpdatePowerShell # ==================== Update PowerShell Modules ==================== @@ -377,31 +381,36 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null - if ($WinGetCommand -and (-not $SkipWinGet)) { - if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { - $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption - } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { - $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption - } else { - Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' - $SkipWinGet = $true - } + if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption + } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption + } else { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping Windows package and CLI updates as a safety precaution.' + $SkipWinGet = $true + $SkipGitHubCli = $true + $SkipCopilotCli = $true + $SkipChocolateyUpdates = $true } if ( - $WinGetCommand -and - (-not $SkipWinGet) -and - ($WindowsOsCaption -match 'Server') + ($WindowsOsCaption -match 'Server') -and + ( + (-not $SkipWinGet) -or + (-not $SkipGitHubCli) -or + (-not $SkipCopilotCli) -or + ($IncludeChocolatey -and (-not $SkipChocolateyUpdates)) + ) ) { # If on Windows Server, prompt to continue before automatically updating packages. - Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' + Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages and CLI tools?' $Yes = New-Object System.Management.Automation.Host.ChoiceDescription '&Yes', 'Description.' $No = New-Object System.Management.Automation.Host.ChoiceDescription '&No', 'Description.' $Options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No) $Title = 'Windows Server OS Found' - $Message = "Do you want to run 'winget update' on your server?" + $Message = 'Do you want to continue with updates on your server?' if (Get-Command -Name 'Get-HostChoice' -ErrorAction SilentlyContinue) { $Result = Get-HostChoice -Title $Title -Message $Message -Options $Options -DefaultChoice 1 } else { @@ -409,10 +418,13 @@ function Update-AllTheThings { } switch ($Result) { 0 { - Write-Verbose 'Continuing with WinGet package updates.' + Write-Verbose 'Continuing with Windows Server updates.' } 1 { $SkipWinGet = $true + $SkipGitHubCli = $true + $SkipCopilotCli = $true + $SkipChocolateyUpdates = $true } } } @@ -513,32 +525,40 @@ function Update-AllTheThings { #endregion UpdateMacOS #region UpdateGitHubCli - & $InvokeOptionalCliUpdate -CommandName 'gh' ` - -DisplayName '[7] Updating GitHub CLI Extensions' ` - -CurrentOperation 'Updating GitHub CLI Extensions' ` - -TargetName 'GitHub CLI extensions' ` - -ActionName 'Upgrade all installed extensions' ` - -PercentComplete 90 ` - -UpdateCommand { - gh extension upgrade --all - } + if (-not $SkipGitHubCli) { + & $InvokeOptionalCliUpdate -CommandName 'gh' ` + -DisplayName '[7] Updating GitHub CLI Extensions' ` + -CurrentOperation 'Updating GitHub CLI Extensions' ` + -TargetName 'GitHub CLI extensions' ` + -ActionName 'Upgrade all installed extensions' ` + -PercentComplete 90 ` + -UpdateCommand { + gh extension upgrade --all + } + } else { + Write-Host '[7] Skipping GitHub CLI Extensions' + } #endregion UpdateGitHubCli #region UpdateCopilotCli - & $InvokeOptionalCliUpdate -CommandName 'copilot' ` - -DisplayName '[8] Updating GitHub Copilot CLI' ` - -CurrentOperation 'Updating GitHub Copilot CLI' ` - -TargetName 'GitHub Copilot CLI' ` - -ActionName 'Update installed CLI' ` - -PercentComplete 95 ` - -UpdateCommand { - copilot update - } + if (-not $SkipCopilotCli) { + & $InvokeOptionalCliUpdate -CommandName 'copilot' ` + -DisplayName '[8] Updating GitHub Copilot CLI' ` + -CurrentOperation 'Updating GitHub Copilot CLI' ` + -TargetName 'GitHub Copilot CLI' ` + -ActionName 'Update installed CLI' ` + -PercentComplete 95 ` + -UpdateCommand { + copilot update + } + } else { + Write-Host '[8] Skipping GitHub Copilot CLI' + } #endregion UpdateCopilotCli #region UpdateChocolatey # Upgrade Chocolatey packages. Need to check for admin to avoid errors/warnings. - if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey) { + if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey -and (-not $SkipChocolateyUpdates)) { # Update the outer progress bar $PercentCompleteOuter = 98 $ProgressParamOuter = @{ diff --git a/docs/Update-AllTheThings.md b/docs/Update-AllTheThings.md index 99728bc7..04310313 100644 --- a/docs/Update-AllTheThings.md +++ b/docs/Update-AllTheThings.md @@ -242,4 +242,4 @@ Version: 0.5.10 ## RELATED LINKS -{{ Fill in the related links here }} +- [Update-AllTheThings](https://day3bits.com/PSPreworkout/Update-AllTheThings) diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index cb60d05b..1763585f 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -153,6 +153,10 @@ function Update-AllTheThings { } } + $SkipGitHubCli = $false + $SkipCopilotCli = $false + $SkipChocolateyUpdates = $false + #region UpdatePowerShell # ==================== Update PowerShell Modules ==================== @@ -275,31 +279,36 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null - if ($WinGetCommand -and (-not $SkipWinGet)) { - if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { - $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption - } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { - $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption - } else { - Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' - $SkipWinGet = $true - } + if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption + } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption + } else { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping Windows package and CLI updates as a safety precaution.' + $SkipWinGet = $true + $SkipGitHubCli = $true + $SkipCopilotCli = $true + $SkipChocolateyUpdates = $true } if ( - $WinGetCommand -and - (-not $SkipWinGet) -and - ($WindowsOsCaption -match 'Server') + ($WindowsOsCaption -match 'Server') -and + ( + (-not $SkipWinGet) -or + (-not $SkipGitHubCli) -or + (-not $SkipCopilotCli) -or + ($IncludeChocolatey -and (-not $SkipChocolateyUpdates)) + ) ) { # If on Windows Server, prompt to continue before automatically updating packages. - Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' + Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages and CLI tools?' $Yes = New-Object System.Management.Automation.Host.ChoiceDescription '&Yes', 'Description.' $No = New-Object System.Management.Automation.Host.ChoiceDescription '&No', 'Description.' $Options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No) $Title = 'Windows Server OS Found' - $Message = "Do you want to run 'winget update' on your server?" + $Message = 'Do you want to continue with updates on your server?' if (Get-Command -Name 'Get-HostChoice' -ErrorAction SilentlyContinue) { $Result = Get-HostChoice -Title $Title -Message $Message -Options $Options -DefaultChoice 1 } else { @@ -307,10 +316,13 @@ function Update-AllTheThings { } switch ($Result) { 0 { - Write-Verbose 'Continuing with WinGet package updates.' + Write-Verbose 'Continuing with Windows Server updates.' } 1 { $SkipWinGet = $true + $SkipGitHubCli = $true + $SkipCopilotCli = $true + $SkipChocolateyUpdates = $true } } } @@ -411,32 +423,40 @@ function Update-AllTheThings { #endregion UpdateMacOS #region UpdateGitHubCli - & $InvokeOptionalCliUpdate -CommandName 'gh' ` - -DisplayName '[7] Updating GitHub CLI Extensions' ` - -CurrentOperation 'Updating GitHub CLI Extensions' ` - -TargetName 'GitHub CLI extensions' ` - -ActionName 'Upgrade all installed extensions' ` - -PercentComplete 90 ` - -UpdateCommand { - gh extension upgrade --all - } + if (-not $SkipGitHubCli) { + & $InvokeOptionalCliUpdate -CommandName 'gh' ` + -DisplayName '[7] Updating GitHub CLI Extensions' ` + -CurrentOperation 'Updating GitHub CLI Extensions' ` + -TargetName 'GitHub CLI extensions' ` + -ActionName 'Upgrade all installed extensions' ` + -PercentComplete 90 ` + -UpdateCommand { + gh extension upgrade --all + } + } else { + Write-Host '[7] Skipping GitHub CLI Extensions' + } #endregion UpdateGitHubCli #region UpdateCopilotCli - & $InvokeOptionalCliUpdate -CommandName 'copilot' ` - -DisplayName '[8] Updating GitHub Copilot CLI' ` - -CurrentOperation 'Updating GitHub Copilot CLI' ` - -TargetName 'GitHub Copilot CLI' ` - -ActionName 'Update installed CLI' ` - -PercentComplete 95 ` - -UpdateCommand { - copilot update - } + if (-not $SkipCopilotCli) { + & $InvokeOptionalCliUpdate -CommandName 'copilot' ` + -DisplayName '[8] Updating GitHub Copilot CLI' ` + -CurrentOperation 'Updating GitHub Copilot CLI' ` + -TargetName 'GitHub Copilot CLI' ` + -ActionName 'Update installed CLI' ` + -PercentComplete 95 ` + -UpdateCommand { + copilot update + } + } else { + Write-Host '[8] Skipping GitHub Copilot CLI' + } #endregion UpdateCopilotCli #region UpdateChocolatey # Upgrade Chocolatey packages. Need to check for admin to avoid errors/warnings. - if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey) { + if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey -and (-not $SkipChocolateyUpdates)) { # Update the outer progress bar $PercentCompleteOuter = 98 $ProgressParamOuter = @{ diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 5d62b1e9..e75b2cdf 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -261,6 +261,23 @@ Describe 'Update-AllTheThings' { Should -Invoke copilot -Exactly 0 } + + It 'Does not run GitHub CLI updates during WhatIf' { + Mock Get-Command { + param($Name) + + if ($Name -in @('gh', 'copilot')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet -WhatIf + + Should -Invoke gh -Exactly 0 + Should -Invoke copilot -Exactly 0 + } } Context 'Windows Server WinGet Prompt' { @@ -360,10 +377,11 @@ Describe 'Update-AllTheThings' { It 'Still runs later CLI updates when WinGet is skipped explicitly' { Mock gh {} Mock copilot {} + Mock Get-HostChoice { 0 } Mock Get-Command { param($Name) - if ($Name -in @('gh', 'copilot')) { + if ($Name -in @('Get-CimInstance', 'Get-HostChoice', 'gh', 'copilot')) { return @{ Name = $Name } } From aff8dfc26df23ca6885838731f0a1edcb1de15b8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:36:24 +0000 Subject: [PATCH 11/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20decouple=20?= =?UTF-8?q?CLI=20updates=20from=20WinGet=20server=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 76 ++++++------------- .../Public/Update-AllTheThings.ps1 | 76 ++++++------------- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 23 ++++++ 3 files changed, 73 insertions(+), 102 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 6836e463..4e26e366 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -255,10 +255,6 @@ function Update-AllTheThings { } } - $SkipGitHubCli = $false - $SkipCopilotCli = $false - $SkipChocolateyUpdates = $false - #region UpdatePowerShell # ==================== Update PowerShell Modules ==================== @@ -385,32 +381,21 @@ function Update-AllTheThings { $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption - } else { - Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping Windows package and CLI updates as a safety precaution.' + } elseif ($WinGetCommand -and (-not $SkipWinGet)) { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' $SkipWinGet = $true - $SkipGitHubCli = $true - $SkipCopilotCli = $true - $SkipChocolateyUpdates = $true } - if ( - ($WindowsOsCaption -match 'Server') -and - ( - (-not $SkipWinGet) -or - (-not $SkipGitHubCli) -or - (-not $SkipCopilotCli) -or - ($IncludeChocolatey -and (-not $SkipChocolateyUpdates)) - ) - ) { + if ($WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. - Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages and CLI tools?' + Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' $Yes = New-Object System.Management.Automation.Host.ChoiceDescription '&Yes', 'Description.' $No = New-Object System.Management.Automation.Host.ChoiceDescription '&No', 'Description.' $Options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No) $Title = 'Windows Server OS Found' - $Message = 'Do you want to continue with updates on your server?' + $Message = "Do you want to run 'winget update' on your server?" if (Get-Command -Name 'Get-HostChoice' -ErrorAction SilentlyContinue) { $Result = Get-HostChoice -Title $Title -Message $Message -Options $Options -DefaultChoice 1 } else { @@ -418,13 +403,10 @@ function Update-AllTheThings { } switch ($Result) { 0 { - Write-Verbose 'Continuing with Windows Server updates.' + Write-Verbose 'Continuing with WinGet package updates.' } 1 { $SkipWinGet = $true - $SkipGitHubCli = $true - $SkipCopilotCli = $true - $SkipChocolateyUpdates = $true } } } @@ -525,40 +507,32 @@ function Update-AllTheThings { #endregion UpdateMacOS #region UpdateGitHubCli - if (-not $SkipGitHubCli) { - & $InvokeOptionalCliUpdate -CommandName 'gh' ` - -DisplayName '[7] Updating GitHub CLI Extensions' ` - -CurrentOperation 'Updating GitHub CLI Extensions' ` - -TargetName 'GitHub CLI extensions' ` - -ActionName 'Upgrade all installed extensions' ` - -PercentComplete 90 ` - -UpdateCommand { - gh extension upgrade --all - } - } else { - Write-Host '[7] Skipping GitHub CLI Extensions' - } + & $InvokeOptionalCliUpdate -CommandName 'gh' ` + -DisplayName '[7] Updating GitHub CLI Extensions' ` + -CurrentOperation 'Updating GitHub CLI Extensions' ` + -TargetName 'GitHub CLI extensions' ` + -ActionName 'Upgrade all installed extensions' ` + -PercentComplete 90 ` + -UpdateCommand { + gh extension upgrade --all + } #endregion UpdateGitHubCli #region UpdateCopilotCli - if (-not $SkipCopilotCli) { - & $InvokeOptionalCliUpdate -CommandName 'copilot' ` - -DisplayName '[8] Updating GitHub Copilot CLI' ` - -CurrentOperation 'Updating GitHub Copilot CLI' ` - -TargetName 'GitHub Copilot CLI' ` - -ActionName 'Update installed CLI' ` - -PercentComplete 95 ` - -UpdateCommand { - copilot update - } - } else { - Write-Host '[8] Skipping GitHub Copilot CLI' - } + & $InvokeOptionalCliUpdate -CommandName 'copilot' ` + -DisplayName '[8] Updating GitHub Copilot CLI' ` + -CurrentOperation 'Updating GitHub Copilot CLI' ` + -TargetName 'GitHub Copilot CLI' ` + -ActionName 'Update installed CLI' ` + -PercentComplete 95 ` + -UpdateCommand { + copilot update + } #endregion UpdateCopilotCli #region UpdateChocolatey # Upgrade Chocolatey packages. Need to check for admin to avoid errors/warnings. - if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey -and (-not $SkipChocolateyUpdates)) { + if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey) { # Update the outer progress bar $PercentCompleteOuter = 98 $ProgressParamOuter = @{ diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 1763585f..b055d675 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -153,10 +153,6 @@ function Update-AllTheThings { } } - $SkipGitHubCli = $false - $SkipCopilotCli = $false - $SkipChocolateyUpdates = $false - #region UpdatePowerShell # ==================== Update PowerShell Modules ==================== @@ -283,32 +279,21 @@ function Update-AllTheThings { $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption - } else { - Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping Windows package and CLI updates as a safety precaution.' + } elseif ($WinGetCommand -and (-not $SkipWinGet)) { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' $SkipWinGet = $true - $SkipGitHubCli = $true - $SkipCopilotCli = $true - $SkipChocolateyUpdates = $true } - if ( - ($WindowsOsCaption -match 'Server') -and - ( - (-not $SkipWinGet) -or - (-not $SkipGitHubCli) -or - (-not $SkipCopilotCli) -or - ($IncludeChocolatey -and (-not $SkipChocolateyUpdates)) - ) - ) { + if ($WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. - Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages and CLI tools?' + Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' $Yes = New-Object System.Management.Automation.Host.ChoiceDescription '&Yes', 'Description.' $No = New-Object System.Management.Automation.Host.ChoiceDescription '&No', 'Description.' $Options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No) $Title = 'Windows Server OS Found' - $Message = 'Do you want to continue with updates on your server?' + $Message = "Do you want to run 'winget update' on your server?" if (Get-Command -Name 'Get-HostChoice' -ErrorAction SilentlyContinue) { $Result = Get-HostChoice -Title $Title -Message $Message -Options $Options -DefaultChoice 1 } else { @@ -316,13 +301,10 @@ function Update-AllTheThings { } switch ($Result) { 0 { - Write-Verbose 'Continuing with Windows Server updates.' + Write-Verbose 'Continuing with WinGet package updates.' } 1 { $SkipWinGet = $true - $SkipGitHubCli = $true - $SkipCopilotCli = $true - $SkipChocolateyUpdates = $true } } } @@ -423,40 +405,32 @@ function Update-AllTheThings { #endregion UpdateMacOS #region UpdateGitHubCli - if (-not $SkipGitHubCli) { - & $InvokeOptionalCliUpdate -CommandName 'gh' ` - -DisplayName '[7] Updating GitHub CLI Extensions' ` - -CurrentOperation 'Updating GitHub CLI Extensions' ` - -TargetName 'GitHub CLI extensions' ` - -ActionName 'Upgrade all installed extensions' ` - -PercentComplete 90 ` - -UpdateCommand { - gh extension upgrade --all - } - } else { - Write-Host '[7] Skipping GitHub CLI Extensions' - } + & $InvokeOptionalCliUpdate -CommandName 'gh' ` + -DisplayName '[7] Updating GitHub CLI Extensions' ` + -CurrentOperation 'Updating GitHub CLI Extensions' ` + -TargetName 'GitHub CLI extensions' ` + -ActionName 'Upgrade all installed extensions' ` + -PercentComplete 90 ` + -UpdateCommand { + gh extension upgrade --all + } #endregion UpdateGitHubCli #region UpdateCopilotCli - if (-not $SkipCopilotCli) { - & $InvokeOptionalCliUpdate -CommandName 'copilot' ` - -DisplayName '[8] Updating GitHub Copilot CLI' ` - -CurrentOperation 'Updating GitHub Copilot CLI' ` - -TargetName 'GitHub Copilot CLI' ` - -ActionName 'Update installed CLI' ` - -PercentComplete 95 ` - -UpdateCommand { - copilot update - } - } else { - Write-Host '[8] Skipping GitHub Copilot CLI' - } + & $InvokeOptionalCliUpdate -CommandName 'copilot' ` + -DisplayName '[8] Updating GitHub Copilot CLI' ` + -CurrentOperation 'Updating GitHub Copilot CLI' ` + -TargetName 'GitHub Copilot CLI' ` + -ActionName 'Update installed CLI' ` + -PercentComplete 95 ` + -UpdateCommand { + copilot update + } #endregion UpdateCopilotCli #region UpdateChocolatey # Upgrade Chocolatey packages. Need to check for admin to avoid errors/warnings. - if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey -and (-not $SkipChocolateyUpdates)) { + if ((Get-Command choco -ErrorAction SilentlyContinue) -and $IncludeChocolatey) { # Update the outer progress bar $PercentCompleteOuter = 98 $ProgressParamOuter = @{ diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index e75b2cdf..070cb51b 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -374,6 +374,29 @@ Describe 'Update-AllTheThings' { Should -Invoke winget -Exactly 0 } + It 'Still runs GitHub CLI updates when WinGet server detection is unavailable' { + Mock gh {} + Mock copilot {} + Mock Get-Command { + param($Name) + + if ($Name -in @('winget', 'gh', 'copilot')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp + + Should -Invoke Write-Warning -Exactly 1 -ParameterFilter { + $Message -match 'Unable to determine the Windows operating system caption' + } + Should -Invoke winget -Exactly 0 + Should -Invoke gh -Exactly 1 -ParameterFilter { ($Arguments -join ' ') -eq 'extension upgrade --all' } + Should -Invoke copilot -Exactly 1 -ParameterFilter { ($Arguments -join ' ') -eq 'update' } + } + It 'Still runs later CLI updates when WinGet is skipped explicitly' { Mock gh {} Mock copilot {} From 5ddfebb39c0a282ff5b4aef8a470d04c80fbeb5a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:37:39 +0000 Subject: [PATCH 12/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20retry=20Win?= =?UTF-8?q?Get=20server=20detection=20with=20WMI=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 30 ++++++++++++++----- .../Public/Update-AllTheThings.ps1 | 30 ++++++++++++++----- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 23 ++++++++++++++ 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 4e26e366..b7677b67 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -377,13 +377,29 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null - if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { - $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption - } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { - $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption - } elseif ($WinGetCommand -and (-not $SkipWinGet)) { - Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' - $SkipWinGet = $true + if ($WinGetCommand -and (-not $SkipWinGet)) { + try { + if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption + } + } catch { + Write-Verbose 'Get-CimInstance failed while checking the Windows operating system caption.' + } + + if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { + try { + if (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption + } + } catch { + Write-Verbose 'Get-WmiObject failed while checking the Windows operating system caption.' + } + } + + if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' + $SkipWinGet = $true + } } if ($WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index b055d675..d9e9eb42 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -275,13 +275,29 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null - if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { - $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption - } elseif (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { - $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption - } elseif ($WinGetCommand -and (-not $SkipWinGet)) { - Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' - $SkipWinGet = $true + if ($WinGetCommand -and (-not $SkipWinGet)) { + try { + if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption + } + } catch { + Write-Verbose 'Get-CimInstance failed while checking the Windows operating system caption.' + } + + if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { + try { + if (Get-Command -Name 'Get-WmiObject' -ErrorAction SilentlyContinue) { + $WindowsOsCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption + } + } catch { + Write-Verbose 'Get-WmiObject failed while checking the Windows operating system caption.' + } + } + + if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' + $SkipWinGet = $true + } } if ($WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 070cb51b..a07cfe7c 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -355,6 +355,29 @@ Describe 'Update-AllTheThings' { } } + It 'Falls back to WMI when CIM is available but throws' { + Mock Get-HostChoice { 0 } + Mock Get-CimInstance { throw 'CIM failure' } + Mock Get-WmiObject { @{ Caption = 'Windows Server 2025 Datacenter' } } + Mock Get-Command { + param($Name) + + if ($Name -in @('Get-CimInstance', 'Get-HostChoice', 'Get-WmiObject', 'winget')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp + + Should -Invoke Get-CimInstance -Exactly 1 -ParameterFilter { $ClassName -eq 'CIM_OperatingSystem' } + Should -Invoke Get-WmiObject -Exactly 1 -ParameterFilter { $Class -eq 'Win32_OperatingSystem' } + Should -Invoke winget -Exactly 1 -ParameterFilter { + ($Arguments -join ' ') -eq 'upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all' + } + } + It 'Skips WinGet when the Windows OS caption cannot be determined' { Mock Get-Command { param($Name) From cfd4dc6daa044679c2925c29044e90c623fb0e0a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:38:22 +0000 Subject: [PATCH 13/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20skip=20WinG?= =?UTF-8?q?et=20server=20prompt=20during=20WhatIf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 2 +- .../Public/Update-AllTheThings.ps1 | 2 +- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index b7677b67..0b89debb 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -402,7 +402,7 @@ function Update-AllTheThings { } } - if ($WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { + if ((-not $WhatIfPreference) -and $WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index d9e9eb42..be6ef5de 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -300,7 +300,7 @@ function Update-AllTheThings { } } - if ($WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { + if ((-not $WhatIfPreference) -and $WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index a07cfe7c..300bd51d 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -332,6 +332,24 @@ Describe 'Update-AllTheThings' { Should -Invoke winget -Exactly 0 } + It 'Skips the Windows Server prompt during WhatIf' { + Mock Get-HostChoice { throw 'prompted' } + Mock Get-Command { + param($Name) + + if ($Name -in @('Get-CimInstance', 'Get-HostChoice', 'winget')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -WhatIf + + Should -Invoke Get-HostChoice -Exactly 0 + Should -Invoke winget -Exactly 0 + } + It 'Falls back to WMI for the server prompt when CIM is unavailable' { Mock Get-HostChoice { 0 } Mock Get-CimInstance {} From 178936654150988aa160141d29be8148eea24797 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:39:32 +0000 Subject: [PATCH 14/30] =?UTF-8?q?=E2=9C=85=20test(cmdlet):=20cover=20packa?= =?UTF-8?q?ged=20WinGet=20safeguards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 32 +++++++----- .../Public/Update-AllTheThings.ps1 | 32 +++++++----- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 50 +++++++++++++++++++ 3 files changed, 88 insertions(+), 26 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 0b89debb..e58ef09c 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -376,8 +376,11 @@ function Update-AllTheThings { if ($IsWindows -or ($PSVersionTable.PSVersion -le [version]'5.1')) { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null + $ShouldUpdateWinGet = $false if ($WinGetCommand -and (-not $SkipWinGet)) { + $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') + try { if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption @@ -402,7 +405,7 @@ function Update-AllTheThings { } } - if ((-not $WhatIfPreference) -and $WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' @@ -423,25 +426,28 @@ function Update-AllTheThings { } 1 { $SkipWinGet = $true + $ShouldUpdateWinGet = $false } } } if (-not $SkipWinGet) { if ($WinGetCommand) { - # Update all winget packages - Write-Host '[4] Updating Winget Packages' - # Update the outer progress bar for winget section - $PercentCompleteOuter = 80 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating Winget Packages' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter + if ($ShouldUpdateWinGet -or $WhatIfPreference) { + # Update all winget packages + Write-Host '[4] Updating Winget Packages' + # Update the outer progress bar for winget section + $PercentCompleteOuter = 80 + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = 'Updating Winget Packages' + Status = "Progress: $PercentCompleteOuter`% Complete" + PercentComplete = $PercentCompleteOuter + } + Write-Progress @ProgressParamOuter } - Write-Progress @ProgressParamOuter - if ($PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages')) { + if ($ShouldUpdateWinGet) { winget upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all } } else { diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index be6ef5de..18d6bc41 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -274,8 +274,11 @@ function Update-AllTheThings { if ($IsWindows -or ($PSVersionTable.PSVersion -le [version]'5.1')) { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null + $ShouldUpdateWinGet = $false if ($WinGetCommand -and (-not $SkipWinGet)) { + $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') + try { if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption @@ -300,7 +303,7 @@ function Update-AllTheThings { } } - if ((-not $WhatIfPreference) -and $WinGetCommand -and (-not $SkipWinGet) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' @@ -321,25 +324,28 @@ function Update-AllTheThings { } 1 { $SkipWinGet = $true + $ShouldUpdateWinGet = $false } } } if (-not $SkipWinGet) { if ($WinGetCommand) { - # Update all winget packages - Write-Host '[4] Updating Winget Packages' - # Update the outer progress bar for winget section - $PercentCompleteOuter = 80 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating Winget Packages' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter + if ($ShouldUpdateWinGet -or $WhatIfPreference) { + # Update all winget packages + Write-Host '[4] Updating Winget Packages' + # Update the outer progress bar for winget section + $PercentCompleteOuter = 80 + $ProgressParamOuter = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = 'Updating Winget Packages' + Status = "Progress: $PercentCompleteOuter`% Complete" + PercentComplete = $PercentCompleteOuter + } + Write-Progress @ProgressParamOuter } - Write-Progress @ProgressParamOuter - if ($PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages')) { + if ($ShouldUpdateWinGet) { winget upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all } } else { diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 300bd51d..e5d2b545 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -2,6 +2,10 @@ BeforeAll { # Import the module or function under test $ModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent $PublicPath = Join-Path -Path $ModulePath -ChildPath 'PSPreworkout\Public' + $RepoRoot = Split-Path -Path $ModulePath -Parent + $PackagedScriptPath = Join-Path -Path $RepoRoot -ChildPath 'Scripts\Update-AllTheThings.ps1' + $script:OriginalIsLinux = $IsLinux + $script:OriginalIsMacOS = $IsMacOS $script:OriginalIsWindows = $IsWindows function Write-PSPreworkoutTelemetry { @@ -100,6 +104,8 @@ BeforeAll { } AfterAll { + Set-Variable -Name IsLinux -Value $script:OriginalIsLinux -Force + Set-Variable -Name IsMacOS -Value $script:OriginalIsMacOS -Force Set-Variable -Name IsWindows -Value $script:OriginalIsWindows -Force } @@ -282,6 +288,8 @@ Describe 'Update-AllTheThings' { Context 'Windows Server WinGet Prompt' { BeforeEach { + Set-Variable -Name IsLinux -Value $false -Force + Set-Variable -Name IsMacOS -Value $false -Force Set-Variable -Name IsWindows -Value $true -Force Mock Set-PSRepository {} Mock Write-Host {} @@ -293,6 +301,8 @@ Describe 'Update-AllTheThings' { } AfterEach { + Set-Variable -Name IsLinux -Value $script:OriginalIsLinux -Force + Set-Variable -Name IsMacOS -Value $script:OriginalIsMacOS -Force Set-Variable -Name IsWindows -Value $script:OriginalIsWindows -Force } @@ -479,4 +489,44 @@ Describe 'Update-AllTheThings' { $Function.Parameters['AcceptPrompts'].ParameterType.Name | Should -Be 'SwitchParameter' } } + + Context 'Packaged Script Safeguards' { + BeforeEach { + Set-Variable -Name IsLinux -Value $false -Force + Set-Variable -Name IsMacOS -Value $false -Force + Set-Variable -Name IsWindows -Value $true -Force + Mock Set-PSRepository {} + Mock Write-Host {} + Mock Write-Progress {} + Mock Write-Verbose {} + Mock Write-Warning {} + Mock winget {} + . $PackagedScriptPath + } + + AfterEach { + Set-Variable -Name IsLinux -Value $script:OriginalIsLinux -Force + Set-Variable -Name IsMacOS -Value $script:OriginalIsMacOS -Force + Set-Variable -Name IsWindows -Value $script:OriginalIsWindows -Force + } + + It 'Skips WinGet in the packaged script when the Windows OS caption cannot be determined' { + Mock Get-Command { + param($Name) + + if ($Name -eq 'winget') { + return @{ Name = 'winget' } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp + + Should -Invoke Write-Warning -Exactly 1 -ParameterFilter { + $Message -match 'Unable to determine the Windows operating system caption' + } + Should -Invoke winget -Exactly 0 + } + } } From 23c21f7619ec33ba79c99cae53e4452d023a197b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:40:13 +0000 Subject: [PATCH 15/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20honor=20Con?= =?UTF-8?q?firm=20when=20guarding=20WinGet=20server=20prompts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 3 ++- .../Public/Update-AllTheThings.ps1 | 3 ++- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index e58ef09c..746f3a59 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -377,6 +377,7 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null $ShouldUpdateWinGet = $false + $SkipServerPrompt = $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') @@ -405,7 +406,7 @@ function Update-AllTheThings { } } - if ($ShouldUpdateWinGet -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and (-not $SkipServerPrompt) -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 18d6bc41..29c03378 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -275,6 +275,7 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null $ShouldUpdateWinGet = $false + $SkipServerPrompt = $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') @@ -303,7 +304,7 @@ function Update-AllTheThings { } } - if ($ShouldUpdateWinGet -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and (-not $SkipServerPrompt) -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index e5d2b545..443005a6 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -360,6 +360,26 @@ Describe 'Update-AllTheThings' { Should -Invoke winget -Exactly 0 } + It 'Skips the Windows Server prompt when Confirm is explicitly false' { + Mock Get-HostChoice { throw 'prompted' } + Mock Get-Command { + param($Name) + + if ($Name -in @('Get-CimInstance', 'Get-HostChoice', 'winget')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -Confirm:$false + + Should -Invoke Get-HostChoice -Exactly 0 + Should -Invoke winget -Exactly 1 -ParameterFilter { + ($Arguments -join ' ') -eq 'upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all' + } + } + It 'Falls back to WMI for the server prompt when CIM is unavailable' { Mock Get-HostChoice { 0 } Mock Get-CimInstance {} From e9c79258a14eacf54e3126a38e7376f7b8e83dce Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:40:53 +0000 Subject: [PATCH 16/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20honor=20Acc?= =?UTF-8?q?eptPrompts=20for=20WinGet=20server=20approvals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 2 +- .../Public/Update-AllTheThings.ps1 | 2 +- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 746f3a59..b42b2593 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -406,7 +406,7 @@ function Update-AllTheThings { } } - if ($ShouldUpdateWinGet -and (-not $SkipServerPrompt) -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and (-not $AcceptPrompts) -and (-not $SkipServerPrompt) -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 29c03378..3f03b400 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -304,7 +304,7 @@ function Update-AllTheThings { } } - if ($ShouldUpdateWinGet -and (-not $SkipServerPrompt) -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and (-not $AcceptPrompts) -and (-not $SkipServerPrompt) -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 443005a6..dc07dea4 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -380,6 +380,26 @@ Describe 'Update-AllTheThings' { } } + It 'Skips the Windows Server prompt when AcceptPrompts is specified' { + Mock Get-HostChoice { throw 'prompted' } + Mock Get-Command { + param($Name) + + if ($Name -in @('Get-CimInstance', 'Get-HostChoice', 'winget')) { + return @{ Name = $Name } + } + + return $null + } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -AcceptPrompts + + Should -Invoke Get-HostChoice -Exactly 0 + Should -Invoke winget -Exactly 1 -ParameterFilter { + ($Arguments -join ' ') -eq 'upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all' + } + } + It 'Falls back to WMI for the server prompt when CIM is unavailable' { Mock Get-HostChoice { 0 } Mock Get-CimInstance {} From b2dc1180fd2b80918dafc1ed4feb7232012dea78 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:41:43 +0000 Subject: [PATCH 17/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20avoid=20dou?= =?UTF-8?q?ble=20confirmation=20for=20WinGet=20safeguards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 13 ++++++++++++- src/PSPreworkout/Public/Update-AllTheThings.ps1 | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index b42b2593..29445e87 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -377,7 +377,18 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null $ShouldUpdateWinGet = $false - $SkipServerPrompt = $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) + $ConfirmHandledByShouldProcess = $false + + if ($PSBoundParameters.ContainsKey('Confirm')) { + $ConfirmHandledByShouldProcess = [bool]$Confirm + } elseif ( + ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and + (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) + ) { + $ConfirmHandledByShouldProcess = $true + } + + $SkipServerPrompt = ($PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm)) -or $ConfirmHandledByShouldProcess if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 3f03b400..7e6b2dd2 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -275,7 +275,18 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null $ShouldUpdateWinGet = $false - $SkipServerPrompt = $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) + $ConfirmHandledByShouldProcess = $false + + if ($PSBoundParameters.ContainsKey('Confirm')) { + $ConfirmHandledByShouldProcess = [bool]$Confirm + } elseif ( + ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and + (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) + ) { + $ConfirmHandledByShouldProcess = $true + } + + $SkipServerPrompt = ($PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm)) -or $ConfirmHandledByShouldProcess if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') From e3184da27cb7007cb03aef483e4df913a284e0b8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:42:22 +0000 Subject: [PATCH 18/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20preserve=20?= =?UTF-8?q?server=20prompts=20unless=20confirmations=20are=20disabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 13 +------------ src/PSPreworkout/Public/Update-AllTheThings.ps1 | 13 +------------ 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 29445e87..b42b2593 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -377,18 +377,7 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null $ShouldUpdateWinGet = $false - $ConfirmHandledByShouldProcess = $false - - if ($PSBoundParameters.ContainsKey('Confirm')) { - $ConfirmHandledByShouldProcess = [bool]$Confirm - } elseif ( - ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and - (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) - ) { - $ConfirmHandledByShouldProcess = $true - } - - $SkipServerPrompt = ($PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm)) -or $ConfirmHandledByShouldProcess + $SkipServerPrompt = $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 7e6b2dd2..3f03b400 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -275,18 +275,7 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null $ShouldUpdateWinGet = $false - $ConfirmHandledByShouldProcess = $false - - if ($PSBoundParameters.ContainsKey('Confirm')) { - $ConfirmHandledByShouldProcess = [bool]$Confirm - } elseif ( - ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and - (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) - ) { - $ConfirmHandledByShouldProcess = $true - } - - $SkipServerPrompt = ($PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm)) -or $ConfirmHandledByShouldProcess + $SkipServerPrompt = $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') From 4c3b618929d1fdf50431487f4fcf04adabf37ca0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:43:06 +0000 Subject: [PATCH 19/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20respect=20b?= =?UTF-8?q?uilt-in=20consent=20before=20server=20prompts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 8 ++++++-- src/PSPreworkout/Public/Update-AllTheThings.ps1 | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index b42b2593..997208ef 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -377,7 +377,11 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null $ShouldUpdateWinGet = $false - $SkipServerPrompt = $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) + $SkipServerPrompt = $AcceptPrompts -or $WhatIfPreference -or ($PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm)) + $ShouldProcessHandlesConsent = ($PSBoundParameters.ContainsKey('Confirm') -and $Confirm) -or ( + ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and + (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) + ) if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') @@ -406,7 +410,7 @@ function Update-AllTheThings { } } - if ($ShouldUpdateWinGet -and (-not $AcceptPrompts) -and (-not $SkipServerPrompt) -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 3f03b400..67b6c8ec 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -275,7 +275,11 @@ function Update-AllTheThings { $WinGetCommand = Get-Command -Name 'winget' -ErrorAction SilentlyContinue $WindowsOsCaption = $null $ShouldUpdateWinGet = $false - $SkipServerPrompt = $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) + $SkipServerPrompt = $AcceptPrompts -or $WhatIfPreference -or ($PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm)) + $ShouldProcessHandlesConsent = ($PSBoundParameters.ContainsKey('Confirm') -and $Confirm) -or ( + ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and + (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) + ) if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') @@ -304,7 +308,7 @@ function Update-AllTheThings { } } - if ($ShouldUpdateWinGet -and (-not $AcceptPrompts) -and (-not $SkipServerPrompt) -and (-not $WhatIfPreference) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' From e3b91424a2feb2ae635c4b77174f3bbff62ca7d0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:44:07 +0000 Subject: [PATCH 20/30] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(cmdlet):=20?= =?UTF-8?q?limit=20WinGet=20server=20checks=20to=20prompt=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 7 ++++++- src/PSPreworkout/Public/Update-AllTheThings.ps1 | 7 ++++++- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 997208ef..787b8408 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -143,6 +143,7 @@ function Update-AllTheThings { [CmdletBinding( SupportsShouldProcess, + ConfirmImpact = 'Medium', HelpUri = 'https://day3bits.com/PSPreworkout/Update-AllTheThings' )] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'This is what we do.')] @@ -382,10 +383,13 @@ function Update-AllTheThings { ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) ) + $NeedServerPrompt = $WinGetCommand -and (-not $SkipWinGet) -and (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') + } + if ($NeedServerPrompt) { try { if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption @@ -407,10 +411,11 @@ function Update-AllTheThings { if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' $SkipWinGet = $true + $ShouldUpdateWinGet = $false } } - if ($ShouldUpdateWinGet -and (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and $NeedServerPrompt -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 67b6c8ec..0211e972 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -41,6 +41,7 @@ function Update-AllTheThings { [CmdletBinding( SupportsShouldProcess, + ConfirmImpact = 'Medium', HelpUri = 'https://day3bits.com/PSPreworkout/Update-AllTheThings' )] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'This is what we do.')] @@ -280,10 +281,13 @@ function Update-AllTheThings { ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) ) + $NeedServerPrompt = $WinGetCommand -and (-not $SkipWinGet) -and (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) if ($WinGetCommand -and (-not $SkipWinGet)) { $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') + } + if ($NeedServerPrompt) { try { if (Get-Command -Name 'Get-CimInstance' -ErrorAction SilentlyContinue) { $WindowsOsCaption = (Get-CimInstance -ClassName CIM_OperatingSystem).Caption @@ -305,10 +309,11 @@ function Update-AllTheThings { if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' $SkipWinGet = $true + $ShouldUpdateWinGet = $false } } - if ($ShouldUpdateWinGet -and (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) -and ($WindowsOsCaption -match 'Server')) { + if ($ShouldUpdateWinGet -and $NeedServerPrompt -and ($WindowsOsCaption -match 'Server')) { # If on Windows Server, prompt to continue before automatically updating packages. Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index dc07dea4..507a9aab 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -416,7 +416,6 @@ Describe 'Update-AllTheThings' { Update-AllTheThings -SkipModules -SkipScripts -SkipHelp - Should -Invoke Get-CimInstance -Exactly 0 Should -Invoke Get-WmiObject -Exactly 1 -ParameterFilter { $Class -eq 'Win32_OperatingSystem' } Should -Invoke winget -Exactly 1 -ParameterFilter { ($Arguments -join ' ') -eq 'upgrade --silent --scope user --accept-package-agreements --accept-source-agreements --all' From ef4fef79c579ae1f9aac1f0960018d7fb56de816 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 14 Sep 2026 00:23:13 +0000 Subject: [PATCH 21/30] Initial plan From d151049fde55fbb7dea1c95753761936469a33df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 14 Sep 2026 00:24:58 +0000 Subject: [PATCH 22/30] =?UTF-8?q?=F0=9F=90=9B=20fix:=20deploy=20Zensical?= =?UTF-8?q?=20docs=20with=20GitHub=20Pages=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- .github/workflows/Deploy Zensical.yml | 39 ++++++++++++++++++++------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/workflows/Deploy Zensical.yml b/.github/workflows/Deploy Zensical.yml index 8d870b9c..c21e02b4 100644 --- a/.github/workflows/Deploy Zensical.yml +++ b/.github/workflows/Deploy Zensical.yml @@ -16,20 +16,21 @@ on: permissions: contents: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: - permissions: - contents: write - runs-on: ubuntu-latest - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true steps: - name: ✅ Checkout Repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: ⚙️ Configure GitHub Pages + uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5 + - name: 🐍 Setup Python uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: @@ -40,7 +41,25 @@ jobs: python -m pip install --upgrade pip pip install -r docs/requirements.txt - - name: 👷‍♂️ Deploy Zensical Docs to GitHub Pages - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: zensical gh-deploy --force + - name: 🏗️ Build Zensical Docs + run: zensical build + + - name: 📦 Upload GitHub Pages artifact + uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3 + with: + path: site + + deploy: + needs: build + runs-on: ubuntu-latest + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - name: 🚀 Deploy GitHub Pages artifact + id: deployment + uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4 From dbe4ae0c790a41f216f7d58dd8ff5301fc155732 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 14 Sep 2026 00:25:35 +0000 Subject: [PATCH 23/30] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20serializ?= =?UTF-8?q?e=20only=20GitHub=20Pages=20deploys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- .github/workflows/Deploy Zensical.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Deploy Zensical.yml b/.github/workflows/Deploy Zensical.yml index c21e02b4..671ab1e4 100644 --- a/.github/workflows/Deploy Zensical.yml +++ b/.github/workflows/Deploy Zensical.yml @@ -16,10 +16,6 @@ on: permissions: contents: read -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - jobs: build: runs-on: ubuntu-latest @@ -52,6 +48,9 @@ jobs: deploy: needs: build runs-on: ubuntu-latest + concurrency: + group: github-pages + cancel-in-progress: true permissions: pages: write id-token: write From 698bc52ff19ef8e09a49d46b8b76a049074e61e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 14 Sep 2026 00:43:56 +0000 Subject: [PATCH 24/30] =?UTF-8?q?=F0=9F=A4=96=20ci:=20guard=20pages=20depl?= =?UTF-8?q?oy=20against=20stale=20runs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- .github/workflows/Deploy Zensical.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/Deploy Zensical.yml b/.github/workflows/Deploy Zensical.yml index 671ab1e4..61aa272e 100644 --- a/.github/workflows/Deploy Zensical.yml +++ b/.github/workflows/Deploy Zensical.yml @@ -19,6 +19,9 @@ permissions: jobs: build: runs-on: ubuntu-latest + permissions: + contents: read + pages: write steps: - name: ✅ Checkout Repository @@ -59,6 +62,24 @@ jobs: url: ${{ steps.deployment.outputs.page_url }} steps: + - name: ✅ Ensure deployment run is current branch head + id: current-head-check + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v8 + with: + script: | + const { owner, repo } = context.repo; + const branch = context.ref.replace("refs/heads/", ""); + const response = await github.rest.repos.getBranch({ owner, repo, branch }); + const latestSha = response.data.commit.sha; + const isCurrentHead = latestSha === context.sha; + + core.setOutput("is_current_head", isCurrentHead ? "true" : "false"); + + if (!isCurrentHead) { + core.notice(`Skipping stale deploy. Run SHA ${context.sha} is behind branch head ${latestSha}.`); + } + - name: 🚀 Deploy GitHub Pages artifact id: deployment + if: steps.current-head-check.outputs.is_current_head == 'true' uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4 From adbc3560e6a6520d740cc3b4dcfb870ea2409462 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 14 Sep 2026 00:56:57 +0000 Subject: [PATCH 25/30] =?UTF-8?q?=F0=9F=A4=96=20ci:=20prevent=20canceling?= =?UTF-8?q?=20in-progress=20pages=20deployments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- .github/workflows/Deploy Zensical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Deploy Zensical.yml b/.github/workflows/Deploy Zensical.yml index 61aa272e..c3a4093c 100644 --- a/.github/workflows/Deploy Zensical.yml +++ b/.github/workflows/Deploy Zensical.yml @@ -53,7 +53,7 @@ jobs: runs-on: ubuntu-latest concurrency: group: github-pages - cancel-in-progress: true + cancel-in-progress: false permissions: pages: write id-token: write From 955effbf61e9b7cda8396697227b47d00b7f8a9a Mon Sep 17 00:00:00 2001 From: Sam Erde <20478745+SamErde@users.noreply.github.com> Date: Sun, 13 Sep 2026 21:19:31 -0400 Subject: [PATCH 26/30] =?UTF-8?q?=F0=9F=A4=96=20ci(pages):=20harden=20docu?= =?UTF-8?q?mentation=20deployment=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add read-only pull request validation, deterministic dependency locking, current action pins, deployment guards, caching, and job timeouts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/Deploy Zensical.yml | 18 +- .github/workflows/Validate Zensical.yml | 36 ++++ docs/requirements.in | 6 + docs/requirements.txt | 268 +++++++++++++++++++++++- 4 files changed, 316 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/Validate Zensical.yml create mode 100644 docs/requirements.in diff --git a/.github/workflows/Deploy Zensical.yml b/.github/workflows/Deploy Zensical.yml index c3a4093c..da6e660e 100644 --- a/.github/workflows/Deploy Zensical.yml +++ b/.github/workflows/Deploy Zensical.yml @@ -19,6 +19,7 @@ permissions: jobs: build: runs-on: ubuntu-latest + timeout-minutes: 15 permissions: contents: read pages: write @@ -28,33 +29,36 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: ⚙️ Configure GitHub Pages - uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5 + uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0 - name: 🐍 Setup Python uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: "3.12" + cache: pip + cache-dependency-path: docs/requirements.txt - name: ➕ Install Zensical - run: | - python -m pip install --upgrade pip - pip install -r docs/requirements.txt + run: python -m pip install --require-hashes --requirement docs/requirements.txt - name: 🏗️ Build Zensical Docs run: zensical build - name: 📦 Upload GitHub Pages artifact - uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3 + uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 with: path: site deploy: needs: build + if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest + timeout-minutes: 15 concurrency: group: github-pages cancel-in-progress: false permissions: + contents: read pages: write id-token: write environment: @@ -64,7 +68,7 @@ jobs: steps: - name: ✅ Ensure deployment run is current branch head id: current-head-check - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v8 + uses: actions/github-script@d746ffe35508b1917358783b479e04febd2b8f71 # v9.0.0 with: script: | const { owner, repo } = context.repo; @@ -82,4 +86,4 @@ jobs: - name: 🚀 Deploy GitHub Pages artifact id: deployment if: steps.current-head-check.outputs.is_current_head == 'true' - uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4 + uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1 diff --git a/.github/workflows/Validate Zensical.yml b/.github/workflows/Validate Zensical.yml new file mode 100644 index 00000000..bb7144b6 --- /dev/null +++ b/.github/workflows/Validate Zensical.yml @@ -0,0 +1,36 @@ +name: 📖 Validate Zensical Docs + +on: + pull_request: + branches: + - main + paths: + - "docs/**" + - ".github/workflows/Deploy Zensical.yml" + - ".github/workflows/Validate Zensical.yml" + - "mkdocs.yml" + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: ✅ Checkout Repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: 🐍 Setup Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: "3.12" + cache: pip + cache-dependency-path: docs/requirements.txt + + - name: ➕ Install Zensical + run: python -m pip install --require-hashes --requirement docs/requirements.txt + + - name: 🏗️ Build Zensical Docs + run: zensical build diff --git a/docs/requirements.in b/docs/requirements.in new file mode 100644 index 00000000..a7994476 --- /dev/null +++ b/docs/requirements.in @@ -0,0 +1,6 @@ +# Direct documentation build requirements +jinja2==3.1.6 # https://pypi.org/project/Jinja2/ +pygments==2.21.0 # https://pypi.org/project/Pygments/ +pymdown-extensions==11.0.2 # https://github.com/facelessuser/pymdown-extensions +zensical==0.0.62 # https://pypi.org/project/zensical/ + diff --git a/docs/requirements.txt b/docs/requirements.txt index 0bc08a1c..960fcaae 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,263 @@ -# Documentation build requirements -jinja2==3.1.6 # https://pypi.org/project/Jinja2/ -pygments==2.21.0 # https://pypi.org/project/Pygments/ -pymdown-extensions==11.0.2 # https://github.com/facelessuser/pymdown-extensions -zensical==0.0.62 # https://pypi.org/project/zensical/ +# This file was autogenerated by uv via the following command: +# uv pip compile docs\requirements.in --python-version 3.12 --generate-hashes --output-file docs\requirements.txt +click==8.5.0 \ + --hash=sha256:255bc9599cf7748b4b1a446ccc735421bd08a2ae529a8b88597d3de5664ee360 \ + --hash=sha256:ba0d2089de75ea0310e2dde03160e6ca10009947fb95a182f9b54021bb272e34 + # via zensical +deepmerge==3.0.1 \ + --hash=sha256:35b39a4cb92cf328d6eca61cbbf65f68a37c2ceb3085f0f853cbb2e52a59fc23 \ + --hash=sha256:35c96f6a68fcf90719a5b31d9f8042ecef6c00fb56836660d33455d0f5cfda65 + # via zensical +jinja2==3.1.6 \ + --hash=sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d \ + --hash=sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67 + # via + # -r docs/requirements.in + # zensical +markdown==3.10.3 \ + --hash=sha256:3589362618f743188b4d955b874402bc814f4f83f544dc207719f4baa7d9c45f \ + --hash=sha256:fa6c92a00a4a3c98b22728c64a935ae1928250ae65058a6ded814d2cc29a4cea + # via + # pymdown-extensions + # zensical +markupsafe==3.0.3 \ + --hash=sha256:0303439a41979d9e74d18ff5e2dd8c43ed6c6001fd40e5bf2e43f7bd9bbc523f \ + --hash=sha256:068f375c472b3e7acbe2d5318dea141359e6900156b5b2ba06a30b169086b91a \ + --hash=sha256:0bf2a864d67e76e5c9a34dc26ec616a66b9888e25e7b9460e1c76d3293bd9dbf \ + --hash=sha256:0db14f5dafddbb6d9208827849fad01f1a2609380add406671a26386cdf15a19 \ + --hash=sha256:0eb9ff8191e8498cca014656ae6b8d61f39da5f95b488805da4bb029cccbfbaf \ + --hash=sha256:0f4b68347f8c5eab4a13419215bdfd7f8c9b19f2b25520968adfad23eb0ce60c \ + --hash=sha256:1085e7fbddd3be5f89cc898938f42c0b3c711fdcb37d75221de2666af647c175 \ + --hash=sha256:116bb52f642a37c115f517494ea5feb03889e04df47eeff5b130b1808ce7c219 \ + --hash=sha256:12c63dfb4a98206f045aa9563db46507995f7ef6d83b2f68eda65c307c6829eb \ + --hash=sha256:133a43e73a802c5562be9bbcd03d090aa5a1fe899db609c29e8c8d815c5f6de6 \ + --hash=sha256:1353ef0c1b138e1907ae78e2f6c63ff67501122006b0f9abad68fda5f4ffc6ab \ + --hash=sha256:15d939a21d546304880945ca1ecb8a039db6b4dc49b2c5a400387cdae6a62e26 \ + --hash=sha256:177b5253b2834fe3678cb4a5f0059808258584c559193998be2601324fdeafb1 \ + --hash=sha256:1872df69a4de6aead3491198eaf13810b565bdbeec3ae2dc8780f14458ec73ce \ + --hash=sha256:1b4b79e8ebf6b55351f0d91fe80f893b4743f104bff22e90697db1590e47a218 \ + --hash=sha256:1b52b4fb9df4eb9ae465f8d0c228a00624de2334f216f178a995ccdcf82c4634 \ + --hash=sha256:1ba88449deb3de88bd40044603fafffb7bc2b055d626a330323a9ed736661695 \ + --hash=sha256:1cc7ea17a6824959616c525620e387f6dd30fec8cb44f649e31712db02123dad \ + --hash=sha256:218551f6df4868a8d527e3062d0fb968682fe92054e89978594c28e642c43a73 \ + --hash=sha256:26a5784ded40c9e318cfc2bdb30fe164bdb8665ded9cd64d500a34fb42067b1c \ + --hash=sha256:2713baf880df847f2bece4230d4d094280f4e67b1e813eec43b4c0e144a34ffe \ + --hash=sha256:2a15a08b17dd94c53a1da0438822d70ebcd13f8c3a95abe3a9ef9f11a94830aa \ + --hash=sha256:2f981d352f04553a7171b8e44369f2af4055f888dfb147d55e42d29e29e74559 \ + --hash=sha256:32001d6a8fc98c8cb5c947787c5d08b0a50663d139f1305bac5885d98d9b40fa \ + --hash=sha256:3524b778fe5cfb3452a09d31e7b5adefeea8c5be1d43c4f810ba09f2ceb29d37 \ + --hash=sha256:3537e01efc9d4dccdf77221fb1cb3b8e1a38d5428920e0657ce299b20324d758 \ + --hash=sha256:35add3b638a5d900e807944a078b51922212fb3dedb01633a8defc4b01a3c85f \ + --hash=sha256:38664109c14ffc9e7437e86b4dceb442b0096dfe3541d7864d9cbe1da4cf36c8 \ + --hash=sha256:3a7e8ae81ae39e62a41ec302f972ba6ae23a5c5396c8e60113e9066ef893da0d \ + --hash=sha256:3b562dd9e9ea93f13d53989d23a7e775fdfd1066c33494ff43f5418bc8c58a5c \ + --hash=sha256:457a69a9577064c05a97c41f4e65148652db078a3a509039e64d3467b9e7ef97 \ + --hash=sha256:4bd4cd07944443f5a265608cc6aab442e4f74dff8088b0dfc8238647b8f6ae9a \ + --hash=sha256:4e885a3d1efa2eadc93c894a21770e4bc67899e3543680313b09f139e149ab19 \ + --hash=sha256:4faffd047e07c38848ce017e8725090413cd80cbc23d86e55c587bf979e579c9 \ + --hash=sha256:509fa21c6deb7a7a273d629cf5ec029bc209d1a51178615ddf718f5918992ab9 \ + --hash=sha256:5678211cb9333a6468fb8d8be0305520aa073f50d17f089b5b4b477ea6e67fdc \ + --hash=sha256:591ae9f2a647529ca990bc681daebdd52c8791ff06c2bfa05b65163e28102ef2 \ + --hash=sha256:5a7d5dc5140555cf21a6fefbdbf8723f06fcd2f63ef108f2854de715e4422cb4 \ + --hash=sha256:69c0b73548bc525c8cb9a251cddf1931d1db4d2258e9599c28c07ef3580ef354 \ + --hash=sha256:6b5420a1d9450023228968e7e6a9ce57f65d148ab56d2313fcd589eee96a7a50 \ + --hash=sha256:722695808f4b6457b320fdc131280796bdceb04ab50fe1795cd540799ebe1698 \ + --hash=sha256:729586769a26dbceff69f7a7dbbf59ab6572b99d94576a5592625d5b411576b9 \ + --hash=sha256:77f0643abe7495da77fb436f50f8dab76dbc6e5fd25d39589a0f1fe6548bfa2b \ + --hash=sha256:795e7751525cae078558e679d646ae45574b47ed6e7771863fcc079a6171a0fc \ + --hash=sha256:7be7b61bb172e1ed687f1754f8e7484f1c8019780f6f6b0786e76bb01c2ae115 \ + --hash=sha256:7c3fb7d25180895632e5d3148dbdc29ea38ccb7fd210aa27acbd1201a1902c6e \ + --hash=sha256:7e68f88e5b8799aa49c85cd116c932a1ac15caaa3f5db09087854d218359e485 \ + --hash=sha256:83891d0e9fb81a825d9a6d61e3f07550ca70a076484292a70fde82c4b807286f \ + --hash=sha256:8485f406a96febb5140bfeca44a73e3ce5116b2501ac54fe953e488fb1d03b12 \ + --hash=sha256:8709b08f4a89aa7586de0aadc8da56180242ee0ada3999749b183aa23df95025 \ + --hash=sha256:8f71bc33915be5186016f675cd83a1e08523649b0e33efdb898db577ef5bb009 \ + --hash=sha256:915c04ba3851909ce68ccc2b8e2cd691618c4dc4c4232fb7982bca3f41fd8c3d \ + --hash=sha256:949b8d66bc381ee8b007cd945914c721d9aba8e27f71959d750a46f7c282b20b \ + --hash=sha256:94c6f0bb423f739146aec64595853541634bde58b2135f27f61c1ffd1cd4d16a \ + --hash=sha256:9a1abfdc021a164803f4d485104931fb8f8c1efd55bc6b748d2f5774e78b62c5 \ + --hash=sha256:9b79b7a16f7fedff2495d684f2b59b0457c3b493778c9eed31111be64d58279f \ + --hash=sha256:a320721ab5a1aba0a233739394eb907f8c8da5c98c9181d1161e77a0c8e36f2d \ + --hash=sha256:a4afe79fb3de0b7097d81da19090f4df4f8d3a2b3adaa8764138aac2e44f3af1 \ + --hash=sha256:ad2cf8aa28b8c020ab2fc8287b0f823d0a7d8630784c31e9ee5edea20f406287 \ + --hash=sha256:b8512a91625c9b3da6f127803b166b629725e68af71f8184ae7e7d54686a56d6 \ + --hash=sha256:bc51efed119bc9cfdf792cdeaa4d67e8f6fcccab66ed4bfdd6bde3e59bfcbb2f \ + --hash=sha256:bdc919ead48f234740ad807933cdf545180bfbe9342c2bb451556db2ed958581 \ + --hash=sha256:bdd37121970bfd8be76c5fb069c7751683bdf373db1ed6c010162b2a130248ed \ + --hash=sha256:be8813b57049a7dc738189df53d69395eba14fb99345e0a5994914a3864c8a4b \ + --hash=sha256:c0c0b3ade1c0b13b936d7970b1d37a57acde9199dc2aecc4c336773e1d86049c \ + --hash=sha256:c47a551199eb8eb2121d4f0f15ae0f923d31350ab9280078d1e5f12b249e0026 \ + --hash=sha256:c4ffb7ebf07cfe8931028e3e4c85f0357459a3f9f9490886198848f4fa002ec8 \ + --hash=sha256:ccfcd093f13f0f0b7fdd0f198b90053bf7b2f02a3927a30e63f3ccc9df56b676 \ + --hash=sha256:d2ee202e79d8ed691ceebae8e0486bd9a2cd4794cec4824e1c99b6f5009502f6 \ + --hash=sha256:d53197da72cc091b024dd97249dfc7794d6a56530370992a5e1a08983ad9230e \ + --hash=sha256:d6dd0be5b5b189d31db7cda48b91d7e0a9795f31430b7f271219ab30f1d3ac9d \ + --hash=sha256:d88b440e37a16e651bda4c7c2b930eb586fd15ca7406cb39e211fcff3bf3017d \ + --hash=sha256:de8a88e63464af587c950061a5e6a67d3632e36df62b986892331d4620a35c01 \ + --hash=sha256:df2449253ef108a379b8b5d6b43f4b1a8e81a061d6537becd5582fba5f9196d7 \ + --hash=sha256:e1c1493fb6e50ab01d20a22826e57520f1284df32f2d8601fdd90b6304601419 \ + --hash=sha256:e1cf1972137e83c5d4c136c43ced9ac51d0e124706ee1c8aa8532c1287fa8795 \ + --hash=sha256:e2103a929dfa2fcaf9bb4e7c091983a49c9ac3b19c9061b6d5427dd7d14d81a1 \ + --hash=sha256:e56b7d45a839a697b5eb268c82a71bd8c7f6c94d6fd50c3d577fa39a9f1409f5 \ + --hash=sha256:e8afc3f2ccfa24215f8cb28dcf43f0113ac3c37c2f0f0806d8c70e4228c5cf4d \ + --hash=sha256:e8fc20152abba6b83724d7ff268c249fa196d8259ff481f3b1476383f8f24e42 \ + --hash=sha256:eaa9599de571d72e2daf60164784109f19978b327a3910d3e9de8c97b5b70cfe \ + --hash=sha256:ec15a59cf5af7be74194f7ab02d0f59a62bdcf1a537677ce67a2537c9b87fcda \ + --hash=sha256:f190daf01f13c72eac4efd5c430a8de82489d9cff23c364c3ea822545032993e \ + --hash=sha256:f34c41761022dd093b4b6896d4810782ffbabe30f2d443ff5f083e0cbbb8c737 \ + --hash=sha256:f3e98bb3798ead92273dc0e5fd0f31ade220f59a266ffd8a4f6065e0a3ce0523 \ + --hash=sha256:f42d0984e947b8adf7dd6dde396e720934d12c506ce84eea8476409563607591 \ + --hash=sha256:f71a396b3bf33ecaa1626c255855702aca4d3d9fea5e051b41ac59a9c1c41edc \ + --hash=sha256:f9e130248f4462aaa8e2552d547f36ddadbeaa573879158d721bbd33dfe4743a \ + --hash=sha256:fed51ac40f757d41b7c48425901843666a6677e3e8eb0abcff09e4ba6e664f50 + # via jinja2 +pygments==2.21.0 \ + --hash=sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9 \ + --hash=sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c + # via + # -r docs/requirements.in + # zensical +pymdown-extensions==11.0.2 \ + --hash=sha256:259910762019732caa1dfd76f3faa62c59f191d46573e80bcb1d13c0f675bbe5 \ + --hash=sha256:9506fcbe66fa355a775b768084334238dd6805020ac4b92bea0c0dda6f8f223d + # via + # -r docs/requirements.in + # zensical +pyyaml==6.0.3 \ + --hash=sha256:00c4bdeba853cc34e7dd471f16b4114f4162dc03e6b7afcc2128711f0eca823c \ + --hash=sha256:0150219816b6a1fa26fb4699fb7daa9caf09eb1999f3b70fb6e786805e80375a \ + --hash=sha256:02893d100e99e03eda1c8fd5c441d8c60103fd175728e23e431db1b589cf5ab3 \ + --hash=sha256:02ea2dfa234451bbb8772601d7b8e426c2bfa197136796224e50e35a78777956 \ + --hash=sha256:0f29edc409a6392443abf94b9cf89ce99889a1dd5376d94316ae5145dfedd5d6 \ + --hash=sha256:10892704fc220243f5305762e276552a0395f7beb4dbf9b14ec8fd43b57f126c \ + --hash=sha256:16249ee61e95f858e83976573de0f5b2893b3677ba71c9dd36b9cf8be9ac6d65 \ + --hash=sha256:1d37d57ad971609cf3c53ba6a7e365e40660e3be0e5175fa9f2365a379d6095a \ + --hash=sha256:1ebe39cb5fc479422b83de611d14e2c0d3bb2a18bbcb01f229ab3cfbd8fee7a0 \ + --hash=sha256:214ed4befebe12df36bcc8bc2b64b396ca31be9304b8f59e25c11cf94a4c033b \ + --hash=sha256:2283a07e2c21a2aa78d9c4442724ec1eb15f5e42a723b99cb3d822d48f5f7ad1 \ + --hash=sha256:22ba7cfcad58ef3ecddc7ed1db3409af68d023b7f940da23c6c2a1890976eda6 \ + --hash=sha256:27c0abcb4a5dac13684a37f76e701e054692a9b2d3064b70f5e4eb54810553d7 \ + --hash=sha256:28c8d926f98f432f88adc23edf2e6d4921ac26fb084b028c733d01868d19007e \ + --hash=sha256:2e71d11abed7344e42a8849600193d15b6def118602c4c176f748e4583246007 \ + --hash=sha256:34d5fcd24b8445fadc33f9cf348c1047101756fd760b4dacb5c3e99755703310 \ + --hash=sha256:37503bfbfc9d2c40b344d06b2199cf0e96e97957ab1c1b546fd4f87e53e5d3e4 \ + --hash=sha256:3c5677e12444c15717b902a5798264fa7909e41153cdf9ef7ad571b704a63dd9 \ + --hash=sha256:3ff07ec89bae51176c0549bc4c63aa6202991da2d9a6129d7aef7f1407d3f295 \ + --hash=sha256:41715c910c881bc081f1e8872880d3c650acf13dfa8214bad49ed4cede7c34ea \ + --hash=sha256:418cf3f2111bc80e0933b2cd8cd04f286338bb88bdc7bc8e6dd775ebde60b5e0 \ + --hash=sha256:44edc647873928551a01e7a563d7452ccdebee747728c1080d881d68af7b997e \ + --hash=sha256:4a2e8cebe2ff6ab7d1050ecd59c25d4c8bd7e6f400f5f82b96557ac0abafd0ac \ + --hash=sha256:4ad1906908f2f5ae4e5a8ddfce73c320c2a1429ec52eafd27138b7f1cbe341c9 \ + --hash=sha256:501a031947e3a9025ed4405a168e6ef5ae3126c59f90ce0cd6f2bfc477be31b7 \ + --hash=sha256:5190d403f121660ce8d1d2c1bb2ef1bd05b5f68533fc5c2ea899bd15f4399b35 \ + --hash=sha256:5498cd1645aa724a7c71c8f378eb29ebe23da2fc0d7a08071d89469bf1d2defb \ + --hash=sha256:5cf4e27da7e3fbed4d6c3d8e797387aaad68102272f8f9752883bc32d61cb87b \ + --hash=sha256:5e0b74767e5f8c593e8c9b5912019159ed0533c70051e9cce3e8b6aa699fcd69 \ + --hash=sha256:5ed875a24292240029e4483f9d4a4b8a1ae08843b9c54f43fcc11e404532a8a5 \ + --hash=sha256:5fcd34e47f6e0b794d17de1b4ff496c00986e1c83f7ab2fb8fcfe9616ff7477b \ + --hash=sha256:5fdec68f91a0c6739b380c83b951e2c72ac0197ace422360e6d5a959d8d97b2c \ + --hash=sha256:6344df0d5755a2c9a276d4473ae6b90647e216ab4757f8426893b5dd2ac3f369 \ + --hash=sha256:64386e5e707d03a7e172c0701abfb7e10f0fb753ee1d773128192742712a98fd \ + --hash=sha256:652cb6edd41e718550aad172851962662ff2681490a8a711af6a4d288dd96824 \ + --hash=sha256:66291b10affd76d76f54fad28e22e51719ef9ba22b29e1d7d03d6777a9174198 \ + --hash=sha256:66e1674c3ef6f541c35191caae2d429b967b99e02040f5ba928632d9a7f0f065 \ + --hash=sha256:6adc77889b628398debc7b65c073bcb99c4a0237b248cacaf3fe8a557563ef6c \ + --hash=sha256:79005a0d97d5ddabfeeea4cf676af11e647e41d81c9a7722a193022accdb6b7c \ + --hash=sha256:7c6610def4f163542a622a73fb39f534f8c101d690126992300bf3207eab9764 \ + --hash=sha256:7f047e29dcae44602496db43be01ad42fc6f1cc0d8cd6c83d342306c32270196 \ + --hash=sha256:8098f252adfa6c80ab48096053f512f2321f0b998f98150cea9bd23d83e1467b \ + --hash=sha256:850774a7879607d3a6f50d36d04f00ee69e7fc816450e5f7e58d7f17f1ae5c00 \ + --hash=sha256:8d1fab6bb153a416f9aeb4b8763bc0f22a5586065f86f7664fc23339fc1c1fac \ + --hash=sha256:8da9669d359f02c0b91ccc01cac4a67f16afec0dac22c2ad09f46bee0697eba8 \ + --hash=sha256:8dc52c23056b9ddd46818a57b78404882310fb473d63f17b07d5c40421e47f8e \ + --hash=sha256:9149cad251584d5fb4981be1ecde53a1ca46c891a79788c0df828d2f166bda28 \ + --hash=sha256:93dda82c9c22deb0a405ea4dc5f2d0cda384168e466364dec6255b293923b2f3 \ + --hash=sha256:96b533f0e99f6579b3d4d4995707cf36df9100d67e0c8303a0c55b27b5f99bc5 \ + --hash=sha256:9c57bb8c96f6d1808c030b1687b9b5fb476abaa47f0db9c0101f5e9f394e97f4 \ + --hash=sha256:9c7708761fccb9397fe64bbc0395abcae8c4bf7b0eac081e12b809bf47700d0b \ + --hash=sha256:9f3bfb4965eb874431221a3ff3fdcddc7e74e3b07799e0e84ca4a0f867d449bf \ + --hash=sha256:a33284e20b78bd4a18c8c2282d549d10bc8408a2a7ff57653c0cf0b9be0afce5 \ + --hash=sha256:a80cb027f6b349846a3bf6d73b5e95e782175e52f22108cfa17876aaeff93702 \ + --hash=sha256:b30236e45cf30d2b8e7b3e85881719e98507abed1011bf463a8fa23e9c3e98a8 \ + --hash=sha256:b3bc83488de33889877a0f2543ade9f70c67d66d9ebb4ac959502e12de895788 \ + --hash=sha256:b865addae83924361678b652338317d1bd7e79b1f4596f96b96c77a5a34b34da \ + --hash=sha256:b8bb0864c5a28024fac8a632c443c87c5aa6f215c0b126c449ae1a150412f31d \ + --hash=sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc \ + --hash=sha256:bdb2c67c6c1390b63c6ff89f210c8fd09d9a1217a465701eac7316313c915e4c \ + --hash=sha256:c1ff362665ae507275af2853520967820d9124984e0f7466736aea23d8611fba \ + --hash=sha256:c2514fceb77bc5e7a2f7adfaa1feb2fb311607c9cb518dbc378688ec73d8292f \ + --hash=sha256:c3355370a2c156cffb25e876646f149d5d68f5e0a3ce86a5084dd0b64a994917 \ + --hash=sha256:c458b6d084f9b935061bc36216e8a69a7e293a2f1e68bf956dcd9e6cbcd143f5 \ + --hash=sha256:d0eae10f8159e8fdad514efdc92d74fd8d682c933a6dd088030f3834bc8e6b26 \ + --hash=sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f \ + --hash=sha256:ebc55a14a21cb14062aa4162f906cd962b28e2e9ea38f9b4391244cd8de4ae0b \ + --hash=sha256:eda16858a3cab07b80edaf74336ece1f986ba330fdb8ee0d6c0d68fe82bc96be \ + --hash=sha256:ee2922902c45ae8ccada2c5b501ab86c36525b883eff4255313a253a3160861c \ + --hash=sha256:efd7b85f94a6f21e4932043973a7ba2613b059c4a000551892ac9f1d11f5baf3 \ + --hash=sha256:f7057c9a337546edc7973c0d3ba84ddcdf0daa14533c2065749c9075001090e6 \ + --hash=sha256:fa160448684b4e94d80416c0fa4aac48967a969efe22931448d853ada8baf926 \ + --hash=sha256:fc09d0aa354569bc501d4e787133afc08552722d3ab34836a80547331bb5d4a0 + # via + # pymdown-extensions + # zensical +tomli==2.4.1 \ + --hash=sha256:01f520d4f53ef97964a240a035ec2a869fe1a37dde002b57ebc4417a27ccd853 \ + --hash=sha256:0d85819802132122da43cb86656f8d1f8c6587d54ae7dcaf30e90533028b49fe \ + --hash=sha256:136443dbd7e1dee43c68ac2694fde36b2849865fa258d39bf822c10e8068eac5 \ + --hash=sha256:1d8591993e228b0c930c4bb0db464bdad97b3289fb981255d6c9a41aedc84b2d \ + --hash=sha256:2190f2e9dd7508d2a90ded5ed369255980a1bcdd58e52f7fe24b8162bf9fedbd \ + --hash=sha256:2c1c351919aca02858f740c6d33adea0c5deea37f9ecca1cc1ef9e884a619d26 \ + --hash=sha256:36d2bd2ad5fb9eaddba5226aa02c8ec3fa4f192631e347b3ed28186d43be6b54 \ + --hash=sha256:3d48a93ee1c9b79c04bb38772ee1b64dcf18ff43085896ea460ca8dec96f35f6 \ + --hash=sha256:47149d5bd38761ac8be13a84864bf0b7b70bc051806bc3669ab1cbc56216b23c \ + --hash=sha256:4ab97e64ccda8756376892c53a72bd1f964e519c77236368527f758fbc36a53a \ + --hash=sha256:4b605484e43cdc43f0954ddae319fb75f04cc10dd80d830540060ee7cd0243cd \ + --hash=sha256:504aa796fe0569bb43171066009ead363de03675276d2d121ac1a4572397870f \ + --hash=sha256:51529d40e3ca50046d7606fa99ce3956a617f9b36380da3b7f0dd3dd28e68cb5 \ + --hash=sha256:52c8ef851d9a240f11a88c003eacb03c31fc1c9c4ec64a99a0f922b93874fda9 \ + --hash=sha256:559db847dc486944896521f68d8190be1c9e719fced785720d2216fe7022b662 \ + --hash=sha256:5a881ab208c0baf688221f8cecc5401bd291d67e38a1ac884d6736cbcd8247e9 \ + --hash=sha256:5cb41aa38891e073ee49d55fbc7839cfdb2bc0e600add13874d048c94aadddd1 \ + --hash=sha256:5e262d41726bc187e69af7825504c933b6794dc3fbd5945e41a79bb14c31f585 \ + --hash=sha256:5ee18d9ebdb417e384b58fe414e8d6af9f4e7a0ae761519fb50f721de398dd4e \ + --hash=sha256:7008df2e7655c495dd12d2a4ad038ff878d4ca4b81fccaf82b714e07eae4402c \ + --hash=sha256:734e20b57ba95624ecf1841e72b53f6e186355e216e5412de414e3c51e5e3c41 \ + --hash=sha256:7c7e1a961a0b2f2472c1ac5b69affa0ae1132c39adcb67aba98568702b9cc23f \ + --hash=sha256:7f86fd587c4ed9dd76f318225e7d9b29cfc5a9d43de44e5754db8d1128487085 \ + --hash=sha256:7f94b27a62cfad8496c8d2513e1a222dd446f095fca8987fceef261225538a15 \ + --hash=sha256:88dceee75c2c63af144e456745e10101eb67361050196b0b6af5d717254dddf7 \ + --hash=sha256:8a650c2dbafa08d42e51ba0b62740dae4ecb9338eefa093aa5c78ceb546fcd5c \ + --hash=sha256:8d65a2fbf9d2f8352685bc1364177ee3923d6baf5e7f43ea4959d7d8bc326a36 \ + --hash=sha256:96481a5786729fd470164b47cdb3e0e58062a496f455ee41b4403be77cb5a076 \ + --hash=sha256:a120733b01c45e9a0c34aeef92bf0cf1d56cfe81ed9d47d562f9ed591a9828ac \ + --hash=sha256:b1d22e6e9387bf4739fbe23bfa80e93f6b0373a7f1b96c6227c32bef95a4d7a8 \ + --hash=sha256:b8c198f8c1805dc42708689ed6864951fd2494f924149d3e4bce7710f8eb5232 \ + --hash=sha256:c2541745709bad0264b7d4705ad453b76ccd191e64aa6f0fc66b69a293a45ece \ + --hash=sha256:c742f741d58a28940ce01d58f0ab2ea3ced8b12402f162f4d534dfe18ba1cd6a \ + --hash=sha256:c7f2c7f2b9ca6bdeef8f0fa897f8e05085923eb091721675170254cbc5b02897 \ + --hash=sha256:d312ef37c91508b0ab2cee7da26ec0b3ed2f03ce12bd87a588d771ae15dcf82d \ + --hash=sha256:d4d8fe59808a54658fcc0160ecfb1b30f9089906c50b23bcb4c69eddc19ec2b4 \ + --hash=sha256:da25dc3563bff5965356133435b757a795a17b17d01dbc0f42fb32447ddfd917 \ + --hash=sha256:eab21f45c7f66c13f2a9e0e1535309cee140182a9cdae1e041d02e47291e8396 \ + --hash=sha256:eb0dc4e38e6a1fd579e5d50369aa2e10acfc9cace504579b2faabb478e76941a \ + --hash=sha256:ec9bfaf3ad2df51ace80688143a6a4ebc09a248f6ff781a9945e51937008fcbc \ + --hash=sha256:ede3e6487c5ef5d28634ba3f31f989030ad6af71edfb0055cbbd14189ff240ba \ + --hash=sha256:f3c6818a1a86dd6dca7ddcaaf76947d5ba31aecc28cb1b67009a5877c9a64f3f \ + --hash=sha256:f758f1b9299d059cc3f6546ae2af89670cb1c4d48ea29c3cacc4fe7de3058257 \ + --hash=sha256:f8f0fc26ec2cc2b965b7a3b87cd19c5c6b8c5e5f436b984e85f486d652285c30 \ + --hash=sha256:fd0409a3653af6c147209d267a0e4243f0ae46b011aa978b1080359fddc9b6cf \ + --hash=sha256:ff18e6a727ee0ab0388507b89d1bc6a22b138d1e2fa56d1ad494586d61d2eae9 \ + --hash=sha256:ff2983983d34813c1aeb0fa89091e76c3a22889ee83ab27c5eeb45100560c049 + # via zensical +zensical==0.0.62 \ + --hash=sha256:111cb32c405ff3a0e162860f81cf8e041447d795657720c36ba3e1b8ed607928 \ + --hash=sha256:2449135eac161eb053bf1138df994b18794e7ab420f73941a65ba66e43b37613 \ + --hash=sha256:4dcc744b1b3f56b85cf23c393a2333dec72e555b263a2fbe3d50ac896cf85468 \ + --hash=sha256:6755d7a2d3de424e07a77f68be080b4e54a34fb564c39434322e8427b9402ace \ + --hash=sha256:7c216f1e33b369aa84826e6e52ecda06059c651793936ec3d64c8b4255a91dcc \ + --hash=sha256:8b04147ac1f109ed3b1fbc74d958323243f35481926765b939638e8933a8bdc6 \ + --hash=sha256:8d4e48fc44faf0b4b77e880e3ad3ec2573644e2ddd59e18c71c829412733495d \ + --hash=sha256:a1efd661fa3241c10c94c8c2b280ac3924bc988b24d0dbf1b8499994b23e12fb \ + --hash=sha256:c468e81adad37517c03de2dda13568c33d9c36b234c34e2b3a04285846d99bd5 \ + --hash=sha256:d2b809aa8aa175f64a362d6a8ab89586ce7dd086b5bf23778f3c3cff68deeae6 + # via -r docs/requirements.in From af70cf02bbe7fff885159102d07663f64be0d096 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 14 Sep 2026 01:55:19 +0000 Subject: [PATCH 27/30] =?UTF-8?q?=F0=9F=90=9B=20fix(cmdlet):=20address=20P?= =?UTF-8?q?R=20review=20thread=20findings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 10 +-- docs/Update-AllTheThings.md | 7 +- .../Public/Update-AllTheThings.ps1 | 10 +-- src/Tests/Unit/Update-AllTheThings.Tests.ps1 | 68 ++++++++++++------- 4 files changed, 60 insertions(+), 35 deletions(-) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 787b8408..6a82c550 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -124,7 +124,7 @@ function Update-AllTheThings { Include Chocolatey package updates. .PARAMETER AcceptPrompts - Automatically accept prompts to install updates in Linux (apt, dnf). + Automatically accept prompts to install updates in Linux (apt, dnf) and continue WinGet updates on Windows Server without showing the extra server confirmation prompt. .EXAMPLE Update-AllTheThings @@ -134,7 +134,7 @@ function Update-AllTheThings { .EXAMPLE Update-AllTheThings -AcceptPrompts - Updates all of the things and automatically accepts Linux package upgrade prompts. + Updates all of the things and automatically accepts Linux package upgrade prompts and the additional WinGet confirmation prompt on Windows Server. .NOTES Author: Sam Erde @@ -184,8 +184,10 @@ function Update-AllTheThings { ) begin { - # Send non-identifying usage statistics to PostHog. - Write-PSPreworkoutTelemetry -EventName $MyInvocation.MyCommand.Name -ParameterNamesOnly $MyInvocation.BoundParameters.Keys + # Send non-identifying usage statistics to PostHog when the helper is available. + if (Get-Command -Name 'Write-PSPreworkoutTelemetry' -ErrorAction SilentlyContinue) { + Write-PSPreworkoutTelemetry -EventName $MyInvocation.MyCommand.Name -ParameterNamesOnly $MyInvocation.BoundParameters.Keys + } # Spacing to get host output from script, winget, and choco all below the progress bar. $Banner = @" diff --git a/docs/Update-AllTheThings.md b/docs/Update-AllTheThings.md index 04310313..43c59c31 100644 --- a/docs/Update-AllTheThings.md +++ b/docs/Update-AllTheThings.md @@ -48,13 +48,16 @@ Updates all of the things it can! Update-AllTheThings -AcceptPrompts -Updates all of the things and automatically accepts Linux package upgrade prompts. +Updates all of the things and automatically accepts Linux package upgrade +prompts and the additional WinGet confirmation prompt on Windows Server. ## PARAMETERS ### -AcceptPrompts -Automatically accept prompts to install updates in Linux (apt, dnf). +Automatically accept prompts to install updates in Linux (apt, dnf) and +continue WinGet updates on Windows Server without showing the extra server +confirmation prompt. ```yaml Type: System.Management.Automation.SwitchParameter diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 0211e972..ea9818cb 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -22,7 +22,7 @@ function Update-AllTheThings { Include Chocolatey package updates. .PARAMETER AcceptPrompts - Automatically accept prompts to install updates in Linux (apt, dnf). + Automatically accept prompts to install updates in Linux (apt, dnf) and continue WinGet updates on Windows Server without showing the extra server confirmation prompt. .EXAMPLE Update-AllTheThings @@ -32,7 +32,7 @@ function Update-AllTheThings { .EXAMPLE Update-AllTheThings -AcceptPrompts - Updates all of the things and automatically accepts Linux package upgrade prompts. + Updates all of the things and automatically accepts Linux package upgrade prompts and the additional WinGet confirmation prompt on Windows Server. .NOTES Author: Sam Erde @@ -82,8 +82,10 @@ function Update-AllTheThings { ) begin { - # Send non-identifying usage statistics to PostHog. - Write-PSPreworkoutTelemetry -EventName $MyInvocation.MyCommand.Name -ParameterNamesOnly $MyInvocation.BoundParameters.Keys + # Send non-identifying usage statistics to PostHog when the helper is available. + if (Get-Command -Name 'Write-PSPreworkoutTelemetry' -ErrorAction SilentlyContinue) { + Write-PSPreworkoutTelemetry -EventName $MyInvocation.MyCommand.Name -ParameterNamesOnly $MyInvocation.BoundParameters.Keys + } # Spacing to get host output from script, winget, and choco all below the progress bar. $Banner = @" diff --git a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 index 507a9aab..ff7543c5 100644 --- a/src/Tests/Unit/Update-AllTheThings.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Tests.ps1 @@ -3,7 +3,7 @@ BeforeAll { $ModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent $PublicPath = Join-Path -Path $ModulePath -ChildPath 'PSPreworkout\Public' $RepoRoot = Split-Path -Path $ModulePath -Parent - $PackagedScriptPath = Join-Path -Path $RepoRoot -ChildPath 'Scripts\Update-AllTheThings.ps1' + $script:PackagedScriptPath = Join-Path -Path $RepoRoot -ChildPath 'Scripts\Update-AllTheThings.ps1' $script:OriginalIsLinux = $IsLinux $script:OriginalIsMacOS = $IsMacOS $script:OriginalIsWindows = $IsWindows @@ -23,6 +23,7 @@ BeforeAll { function Test-IsElevated { [CmdletBinding()] + [OutputType([bool])] param() return $false @@ -60,6 +61,7 @@ BeforeAll { function Get-HostChoice { [CmdletBinding()] + [OutputType([int])] param( [Parameter()] [string]$Title, @@ -78,28 +80,6 @@ BeforeAll { return 0 } - function Get-CimInstance { - [CmdletBinding()] - param( - [Parameter()] - [string]$ClassName - ) - - $ClassName | Out-Null - return @{ Caption = 'Windows 11' } - } - - function Get-WmiObject { - [CmdletBinding()] - param( - [Parameter()] - [string]$Class - ) - - $Class | Out-Null - return @{ Caption = 'Windows 11' } - } - . (Join-Path -Path $PublicPath -ChildPath 'Update-AllTheThings.ps1') } @@ -162,6 +142,7 @@ Describe 'Update-AllTheThings' { $Help = Get-Help Update-AllTheThings -Parameter AcceptPrompts $Help | Should -Not -BeNullOrEmpty $Help.Description.Text | Should -Match 'accept prompts.*Linux' + $Help.Description.Text | Should -Match 'WinGet.*Windows Server' } It 'Should have examples in help documentation' { @@ -291,16 +272,35 @@ Describe 'Update-AllTheThings' { Set-Variable -Name IsLinux -Value $false -Force Set-Variable -Name IsMacOS -Value $false -Force Set-Variable -Name IsWindows -Value $true -Force + Set-Item -Path Function:\Get-CimInstance -Value { + param( + [Parameter()] + [string]$ClassName + ) + + $ClassName | Out-Null + return @{ Caption = 'Windows Server 2025 Datacenter' } + } + Set-Item -Path Function:\Get-WmiObject -Value { + param( + [Parameter()] + [string]$Class + ) + + $Class | Out-Null + return @{ Caption = 'Windows Server 2025 Datacenter' } + } Mock Set-PSRepository {} Mock Write-Host {} Mock Write-Progress {} Mock Write-Verbose {} Mock Write-Warning {} Mock winget {} - Mock Get-CimInstance { @{ Caption = 'Windows Server 2025 Datacenter' } } } AfterEach { + Remove-Item -Path Function:\Get-CimInstance -ErrorAction SilentlyContinue + Remove-Item -Path Function:\Get-WmiObject -ErrorAction SilentlyContinue Set-Variable -Name IsLinux -Value $script:OriginalIsLinux -Force Set-Variable -Name IsMacOS -Value $script:OriginalIsMacOS -Force Set-Variable -Name IsWindows -Value $script:OriginalIsWindows -Force @@ -535,12 +535,13 @@ Describe 'Update-AllTheThings' { Set-Variable -Name IsMacOS -Value $false -Force Set-Variable -Name IsWindows -Value $true -Force Mock Set-PSRepository {} + Mock Set-PSResourceRepository {} Mock Write-Host {} Mock Write-Progress {} Mock Write-Verbose {} Mock Write-Warning {} Mock winget {} - . $PackagedScriptPath + . $script:PackagedScriptPath } AfterEach { @@ -567,5 +568,22 @@ Describe 'Update-AllTheThings' { } Should -Invoke winget -Exactly 0 } + + It 'Does not require telemetry helpers in the packaged script' { + Remove-Item -Path Function:\Write-PSPreworkoutTelemetry -ErrorAction SilentlyContinue + Mock gh {} + Mock copilot {} + Mock Get-Command { + param($Name) + + if ($Name -eq 'Write-PSPreworkoutTelemetry') { + return $null + } + + return $null + } -ParameterFilter { $Name -eq 'Write-PSPreworkoutTelemetry' } + + { Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet -WhatIf } | Should -Not -Throw + } } } From 231ccc1dee2e544bd81c59acc96b4725d4197bf1 Mon Sep 17 00:00:00 2001 From: Sam Erde <20478745+SamErde@users.noreply.github.com> Date: Mon, 14 Sep 2026 09:24:22 -0400 Subject: [PATCH 28/30] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(cmdlet):=20?= =?UTF-8?q?simplify=20Update-AllTheThings=20orchestration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract package-manager and PowerShell update stages into focused private helpers, centralize progress and native command handling, and expand cross-version Pester coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 934 +++++++++++------- Scripts/Update-AllTheThings_Build.ps1 | 9 + Scripts/Update-AllTheThings_ScriptInfo.ps1 | 4 +- docs/Update-AllTheThings.md | 6 +- .../Private/Invoke-UpdateNativeCommand.ps1 | 54 + .../Private/Set-UpdateRepositoryTrust.ps1 | 32 + .../Private/Update-ChocolateyPackage.ps1 | 53 + .../Private/Update-LinuxPackage.ps1 | 58 ++ .../Private/Update-MacOSPackage.ps1 | 28 + .../Private/Update-OptionalCli.ps1 | 75 ++ .../Private/Update-PowerShellArtifact.ps1 | 98 ++ .../Private/Update-WinGetPackage.ps1 | 72 ++ .../Write-UpdateAllTheThingsProgress.ps1 | 50 + .../Public/Update-AllTheThings.ps1 | 400 +------- .../Update-AllTheThings.TestHelpers.ps1 | 9 + ...Invoke-UpdateAllTheThingsCompatibility.ps1 | 3 + .../Unit/Update-AllTheThings.Cli.Tests.ps1 | 38 +- .../Update-AllTheThings.Helpers.Tests.ps1 | 52 + ...pdate-AllTheThings.Orchestration.Tests.ps1 | 82 ++ ...ate-AllTheThings.PackageManagers.Tests.ps1 | 100 ++ .../Update-AllTheThings.PowerShell.Tests.ps1 | 54 + .../Unit/Update-AllTheThings.WinGet.Tests.ps1 | 35 +- 22 files changed, 1461 insertions(+), 785 deletions(-) create mode 100644 src/PSPreworkout/Private/Invoke-UpdateNativeCommand.ps1 create mode 100644 src/PSPreworkout/Private/Set-UpdateRepositoryTrust.ps1 create mode 100644 src/PSPreworkout/Private/Update-ChocolateyPackage.ps1 create mode 100644 src/PSPreworkout/Private/Update-LinuxPackage.ps1 create mode 100644 src/PSPreworkout/Private/Update-MacOSPackage.ps1 create mode 100644 src/PSPreworkout/Private/Update-OptionalCli.ps1 create mode 100644 src/PSPreworkout/Private/Update-PowerShellArtifact.ps1 create mode 100644 src/PSPreworkout/Private/Update-WinGetPackage.ps1 create mode 100644 src/PSPreworkout/Private/Write-UpdateAllTheThingsProgress.ps1 create mode 100644 src/Tests/Unit/Update-AllTheThings.Orchestration.Tests.ps1 create mode 100644 src/Tests/Unit/Update-AllTheThings.PackageManagers.Tests.ps1 create mode 100644 src/Tests/Unit/Update-AllTheThings.PowerShell.Tests.ps1 diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index 20588b3a..fc62d769 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -1,6 +1,6 @@ <#PSScriptInfo -.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, winget). -.VERSION 0.5.10 +.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, WinGet). +.VERSION 0.6.0 .GUID 3a1a1ec9-0ef6-4f84-963d-be1505dab6a8 .AUTHOR Sam Erde .COPYRIGHT (c) 2024 Sam Erde. All rights reserved. @@ -55,7 +55,6 @@ function Get-PSPreworkoutPlatform { if ($PSVersionTable.PSEdition -eq 'Desktop') { return 'Windows' } - if (Get-Variable -Name IsWindows -ValueOnly -ErrorAction SilentlyContinue) { return 'Windows' } @@ -71,6 +70,112 @@ function Get-PSPreworkoutPlatform { return 'Unknown' } +function Write-UpdateAllTheThingsProgress { + <# + .SYNOPSIS + Writes progress for Update-AllTheThings. + + .DESCRIPTION + Centralizes the parent progress record used by Update-AllTheThings and its + private update helpers. + + .PARAMETER CurrentOperation + The operation currently being performed. + + .PARAMETER PercentComplete + The percentage of the overall update that is complete. + + .PARAMETER Completed + Completes and removes the progress record. + + .OUTPUTS + None + #> + + [CmdletBinding()] + param( + [Parameter()] + [ValidateNotNullOrEmpty()] + [string]$CurrentOperation, + + [Parameter()] + [ValidateRange(0, 100)] + [int]$PercentComplete = 0, + + [Parameter()] + [switch]$Completed + ) + + if ($Completed) { + Write-Progress -Id 0 -Activity 'Update Everything' -Completed + return + } + + $ProgressParameters = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = $CurrentOperation + Status = "Progress: $PercentComplete`% Complete" + PercentComplete = $PercentComplete + } + Write-Progress @ProgressParameters +} + +function Invoke-UpdateNativeCommand { + <# + .SYNOPSIS + Invokes a native update command and validates its exit code. + + .DESCRIPTION + Provides consistent invocation and explicit failure handling for native + package-manager commands. + + .PARAMETER Name + The native command to invoke. + + .PARAMETER ArgumentList + Arguments passed to the native command. + + .PARAMETER FailureMessage + Context included in the terminating error when the command fails. + + .PARAMETER Command + An invocation seam used by unit tests. + + .OUTPUTS + None + #> + + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$Name, + + [Parameter()] + [AllowEmptyCollection()] + [string[]]$ArgumentList = @(), + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$FailureMessage, + + [Parameter(DontShow)] + [ValidateNotNull()] + [scriptblock]$Command = { + param($CommandName, $CommandArguments) + + & $CommandName @CommandArguments | Out-Host + return $LASTEXITCODE + } + ) + + $ExitCode = & $Command $Name $ArgumentList + if ($ExitCode -ne 0) { + throw "$FailureMessage failed with exit code $ExitCode." + } +} + function Get-CimOperatingSystemCaption { <# .SYNOPSIS @@ -279,6 +384,429 @@ function Invoke-GitHubCopilotCliUpdate { } } +function Set-UpdateRepositoryTrust { + <# + .SYNOPSIS + Trusts supported PowerShell Gallery repositories. + + .DESCRIPTION + Configures PSGallery as trusted for the installed PowerShellGet and + PSResourceGet clients. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param() + + Write-Verbose 'Set the PowerShell Gallery as a trusted installation source.' + + if ( + (Test-PSPreworkoutCommand -Name 'Set-PSRepository') -and + $PSCmdlet.ShouldProcess('PSGallery', 'Set PowerShellGet repository as trusted') + ) { + Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted + } + + if ( + (Test-PSPreworkoutCommand -Name 'Set-PSResourceRepository') -and + $PSCmdlet.ShouldProcess('PSGallery', 'Set PSResourceGet repository as trusted') + ) { + Set-PSResourceRepository -Name 'PSGallery' -Trusted + } +} + +function Update-PowerShellArtifact { + <# + .SYNOPSIS + Updates installed PowerShell modules, scripts, and help. + + .DESCRIPTION + Handles PowerShell-native update operations and their progress reporting. + + .PARAMETER SkipModules + Skips installed module updates. + + .PARAMETER SkipScripts + Skips installed script updates. + + .PARAMETER SkipHelp + Skips PowerShell help updates. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter()] + [switch]$SkipModules, + + [Parameter()] + [switch]$SkipScripts, + + [Parameter()] + [switch]$SkipHelp + ) + + Write-UpdateAllTheThingsProgress -CurrentOperation 'Getting Installed PowerShell Modules' -PercentComplete 1 + + if ($SkipModules) { + Write-Information '[1] Skipping PowerShell Modules' -InformationAction Continue + } elseif (-not (Test-PSPreworkoutCommand -Name 'Get-InstalledModule')) { + Write-Warning 'Get-InstalledModule was not found. Skipping PowerShell module updates.' + } else { + Write-Information '[1] Getting Installed PowerShell Modules' -InformationAction Continue + $Modules = @(Get-InstalledModule) + Write-Information "[2] Updating $($Modules.Count) PowerShell Modules" -InformationAction Continue + + $ModuleIndex = 0 + foreach ($Module in $Modules) { + ++$ModuleIndex + $ModulePercent = [math]::Ceiling(($ModuleIndex / $Modules.Count) * 100) + $OverallPercent = [math]::Ceiling(10 + (60 * ($ModulePercent / 100))) + + Write-UpdateAllTheThingsProgress -CurrentOperation "Updating PowerShell module $($Module.Name)" -PercentComplete $OverallPercent + Write-Progress -Id 1 -ParentId 0 -Activity 'Updating PowerShell Modules' ` + -CurrentOperation $Module.Name -Status "Progress: $ModulePercent`% Complete" ` + -PercentComplete $ModulePercent + + if ($Module.Version -match 'alpha|beta|prerelease|preview') { + Write-Information "`t`tSkipping $($Module.Name) because a prerelease version is currently installed." -InformationAction Continue + continue + } + + try { + if ($PSCmdlet.ShouldProcess($Module.Name, 'Update PowerShell module')) { + Update-Module -Name $Module.Name + } + } catch [Microsoft.PowerShell.Commands.WriteErrorException] { + Write-Warning "Unable to update PowerShell module '$($Module.Name)': $($_.Exception.Message)" + } + } + } + + Write-Progress -Id 1 -Activity 'Updating PowerShell Modules' -Completed + + if ($SkipScripts) { + Write-Information '[2] Skipping PowerShell Scripts' -InformationAction Continue + } elseif (-not (Test-PSPreworkoutCommand -Name 'Update-Script')) { + Write-Warning 'Update-Script was not found. Skipping PowerShell script updates.' + } else { + Write-Information '[2] Updating PowerShell Scripts' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('Installed PowerShell scripts', 'Update scripts')) { + Update-Script + } + } + + Write-UpdateAllTheThingsProgress -CurrentOperation 'Updating PowerShell Help' -PercentComplete 70 + + if ($SkipHelp) { + Write-Information '[3] Skipping PowerShell Help' -InformationAction Continue + } else { + Write-Information '[3] Updating PowerShell Help' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('PowerShell help files', 'Update help')) { + if ((Get-Culture).LCID -eq 127) { + Update-Help -UICulture en-US -ErrorAction SilentlyContinue + } else { + Update-Help -ErrorAction SilentlyContinue + } + } + } +} + +function Update-WinGetPackage { + <# + .SYNOPSIS + Updates user-scoped WinGet packages. + + .DESCRIPTION + Applies Windows Server safeguards before invoking WinGet. + + .PARAMETER Skip + Skips WinGet package updates. + + .PARAMETER AcceptPrompts + Bypasses the additional Windows Server confirmation prompt. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter()] + [switch]$Skip, + + [Parameter()] + [switch]$AcceptPrompts + ) + + if ($Skip) { + Write-Information '[4] Skipping WinGet' -InformationAction Continue + return + } + + if (-not (Test-PSPreworkoutCommand -Name 'winget')) { + Write-Information '[4] WinGet was not found. Skipping WinGet update.' -InformationAction Continue + return + } + + $ShouldUpdate = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') + $SkipServerPrompt = $AcceptPrompts -or $WhatIfPreference -or ( + $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) + ) + $ShouldProcessHandlesConsent = ($PSBoundParameters.ContainsKey('Confirm') -and $Confirm) -or ( + ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and + (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) + ) + $NeedServerPrompt = (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) + + if ($NeedServerPrompt) { + $WindowsOsCaption = Get-WindowsOperatingSystemCaption + if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' + return + } + + if ($ShouldUpdate -and ($WindowsOsCaption -match 'Server')) { + Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' + if ((Read-WinGetServerChoice) -ne 0) { + return + } + Write-Verbose 'Continuing with WinGet package updates.' + } + } + + if ($ShouldUpdate -or $WhatIfPreference) { + Write-Information '[4] Updating WinGet Packages' -InformationAction Continue + Write-UpdateAllTheThingsProgress -CurrentOperation 'Updating WinGet Packages' -PercentComplete 80 + } + + if ($ShouldUpdate) { + Invoke-WinGetUpgrade + } +} + +function Update-LinuxPackage { + <# + .SYNOPSIS + Updates packages with supported Linux package managers. + + .DESCRIPTION + Updates apt and dnf packages, using sudo only when the current process is + not elevated. + + .PARAMETER AcceptPrompts + Passes the non-interactive acceptance argument to package managers. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter()] + [switch]$AcceptPrompts + ) + + $AptAvailable = Test-PSPreworkoutCommand -Name 'apt' + $DnfAvailable = Test-PSPreworkoutCommand -Name 'dnf' + if ((-not $AptAvailable) -and (-not $DnfAvailable)) { + return + } + + $NeedsSudo = -not (Test-IsElevated) + + if ($AptAvailable) { + Write-Information '[5] Updating apt packages.' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('apt packages', 'Update and upgrade packages')) { + $CommandName = if ($NeedsSudo) { 'sudo' } else { 'apt' } + $UpdateArguments = if ($NeedsSudo) { @('apt', 'update') } else { @('update') } + [string[]]$UpgradeArguments = if ($NeedsSudo) { @('apt', 'upgrade') } else { @('upgrade') } + if ($AcceptPrompts) { + $UpgradeArguments += '-y' + } + + Invoke-UpdateNativeCommand -Name $CommandName -ArgumentList $UpdateArguments -FailureMessage 'apt package index update' + Invoke-UpdateNativeCommand -Name $CommandName -ArgumentList $UpgradeArguments -FailureMessage 'apt package upgrade' + } + } + + if ($DnfAvailable) { + Write-Information '[5] Updating dnf packages.' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('dnf packages', 'Update packages')) { + $CommandName = if ($NeedsSudo) { 'sudo' } else { 'dnf' } + [string[]]$Arguments = if ($NeedsSudo) { @('dnf', 'update') } else { @('update') } + if ($AcceptPrompts) { + $Arguments += '-y' + } + + Invoke-UpdateNativeCommand -Name $CommandName -ArgumentList $Arguments -FailureMessage 'dnf package update' + } + } +} + +function Update-MacOSPackage { + <# + .SYNOPSIS + Updates supported macOS software. + + .DESCRIPTION + Lists macOS software updates and updates Homebrew packages when Homebrew is + installed. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param() + + if ($PSCmdlet.ShouldProcess('macOS software updates', 'List available updates')) { + Invoke-UpdateNativeCommand -Name 'softwareupdate' -ArgumentList '-l' -FailureMessage 'macOS software update query' + } + + if (Test-PSPreworkoutCommand -Name 'brew') { + Write-Information '[6] Updating brew packages.' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('Homebrew packages', 'Update and upgrade packages')) { + Invoke-UpdateNativeCommand -Name 'brew' -ArgumentList 'update' -FailureMessage 'Homebrew update' + Invoke-UpdateNativeCommand -Name 'brew' -ArgumentList 'upgrade' -FailureMessage 'Homebrew upgrade' + } + } +} + +function Update-OptionalCli { + <# + .SYNOPSIS + Updates an optional command-line tool. + + .DESCRIPTION + Runs a supplied update command when its command-line tool is installed. + + .PARAMETER CommandName + The command used to detect whether the tool is installed. + + .PARAMETER DisplayName + The status text displayed to the user. + + .PARAMETER CurrentOperation + The operation shown in the progress record. + + .PARAMETER TargetName + The ShouldProcess target. + + .PARAMETER ActionName + The ShouldProcess action. + + .PARAMETER PercentComplete + The overall completion percentage. + + .PARAMETER UpdateCommand + The update operation to invoke. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$CommandName, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$DisplayName, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$CurrentOperation, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$TargetName, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$ActionName, + + [Parameter(Mandatory)] + [ValidateRange(0, 100)] + [int]$PercentComplete, + + [Parameter(Mandatory)] + [ValidateNotNull()] + [scriptblock]$UpdateCommand + ) + + if (-not (Test-PSPreworkoutCommand -Name $CommandName)) { + Write-Verbose "$DisplayName was skipped because $CommandName was not found." + return + } + + Write-Information $DisplayName -InformationAction Continue + Write-UpdateAllTheThingsProgress -CurrentOperation $CurrentOperation -PercentComplete $PercentComplete + if ($PSCmdlet.ShouldProcess($TargetName, $ActionName)) { + & $UpdateCommand + } +} + +function Update-ChocolateyPackage { + <# + .SYNOPSIS + Updates Chocolatey and installed Chocolatey packages. + + .DESCRIPTION + Optionally configures Chocolatey features when elevated, then updates + Chocolatey and all installed packages. + + .PARAMETER Include + Enables Chocolatey package updates. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter()] + [switch]$Include + ) + + if ((-not $Include) -or (-not (Test-PSPreworkoutCommand -Name 'choco'))) { + Write-Information '[9] Skipping Chocolatey' -InformationAction Continue + return + } + + Write-UpdateAllTheThingsProgress -CurrentOperation 'Updating Chocolatey Packages' -PercentComplete 98 + Write-Information '[9] Updating Chocolatey Packages' -InformationAction Continue + + if (Test-IsElevated) { + if ($PSCmdlet.ShouldProcess('Chocolatey features', 'Enable global confirmation and disable non-elevated warnings')) { + Invoke-UpdateNativeCommand -Name 'choco' -ArgumentList @( + 'feature', 'enable', '-n=allowGlobalConfirmation' + ) -FailureMessage 'Chocolatey global confirmation configuration' + Invoke-UpdateNativeCommand -Name 'choco' -ArgumentList @( + 'feature', 'disable', '--name=showNonElevatedWarnings' + ) -FailureMessage 'Chocolatey non-elevated warning configuration' + } + } else { + Write-Verbose "Run once as an administrator to disable Chocolatey's showNonElevatedWarnings." -Verbose + } + + if ($PSCmdlet.ShouldProcess('Chocolatey packages', 'Upgrade Chocolatey and all packages')) { + $UpgradeArguments = @('-y', '--limit-output', '--accept-license', '--no-color') + $SelfUpdateArguments = @('upgrade', 'chocolatey') + $UpgradeArguments + $PackageUpdateArguments = @('upgrade', 'all') + $UpgradeArguments + Invoke-UpdateNativeCommand -Name 'choco' -ArgumentList $SelfUpdateArguments -FailureMessage 'Chocolatey self-update' + Invoke-UpdateNativeCommand -Name 'choco' -ArgumentList $PackageUpdateArguments -FailureMessage 'Chocolatey package update' + } + + Write-Information ' ' -InformationAction Continue +} + function Test-IsElevated { <# .SYNOPSIS @@ -379,7 +907,7 @@ function Update-AllTheThings { Update all the things! .DESCRIPTION - A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, winget). + A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, WinGet). .PARAMETER SkipModules Skip the step that updates PowerShell modules. @@ -391,7 +919,7 @@ function Update-AllTheThings { Skip the step that updates PowerShell help. .PARAMETER SkipWinGet - Skip the step the updates WinGet packages. + Skip the step that updates WinGet packages. .PARAMETER IncludeChocolatey Include Chocolatey package updates. @@ -411,7 +939,7 @@ function Update-AllTheThings { .NOTES Author: Sam Erde - Version: 0.5.10 + Version: 0.6.0 #> [CmdletBinding( @@ -425,43 +953,35 @@ function Update-AllTheThings { param ( # Skip the step that updates PowerShell modules [Parameter()] - [switch] - $SkipModules, + [switch]$SkipModules, # Skip the step that updates PowerShell scripts [Parameter()] - [switch] - $SkipScripts, + [switch]$SkipScripts, # Skip the step that updates PowerShell help [Parameter()] - [switch] - $SkipHelp, + [switch]$SkipHelp, # Skip the step that updates WinGet packages [Parameter()] - [switch] - $SkipWinGet, + [switch]$SkipWinGet, - # Skip the step that updates Chocolatey packages + # Include Chocolatey package updates [Parameter()] [Alias('SkipChoco')] - [switch] - $IncludeChocolatey, + [switch]$IncludeChocolatey, - # Automatically accept prompts to install updates in Linux + # Automatically accept prompts to install updates [Parameter()] - [switch] - $AcceptPrompts + [switch]$AcceptPrompts ) begin { - # Send non-identifying usage statistics to PostHog when the helper is available. if (Test-PSPreworkoutCommand -Name 'Write-PSPreworkoutTelemetry') { Write-PSPreworkoutTelemetry -EventName $MyInvocation.MyCommand.Name -ParameterNamesOnly $MyInvocation.BoundParameters.Keys } - # Spacing to get host output from script, winget, and choco all below the progress bar. $Banner = @" __ __ __ __ ___ ____ / / / /__ ___/ /__ _/ /____ / _ | / / / @@ -471,325 +991,42 @@ function Update-AllTheThings { /_ __/ / ___ /_ __/ / (_)__ ___ ____ / / / _ \/ -_) / / / _ \/ / _ \/ _ `(_-< /_/ /_//_/\__/ /_/ /_//_/_/_//_/\_, /___/ - /___/ v0.5.10 + /___/ v0.6.0 "@ Write-Host $Banner - } # end begin block + } process { - $Platform = Get-PSPreworkoutPlatform - - Write-Verbose 'Set the PowerShell Gallery as a trusted installation source.' - if ( - (Test-PSPreworkoutCommand -Name 'Set-PSRepository') -and - $PSCmdlet.ShouldProcess('PSGallery', 'Set PowerShellGet repository as trusted') - ) { - Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted - } - if (Test-PSPreworkoutCommand -Name 'Set-PSResourceRepository') { - if ($PSCmdlet.ShouldProcess('PSGallery', 'Set PSResourceGet repository as trusted')) { - Set-PSResourceRepository -Name 'PSGallery' -Trusted - } - } - - $InvokeOptionalCliUpdate = { - param( - [Parameter(Mandatory)] - [string]$CommandName, - - [Parameter(Mandatory)] - [string]$DisplayName, - - [Parameter(Mandatory)] - [string]$CurrentOperation, - - [Parameter(Mandatory)] - [string]$TargetName, - - [Parameter(Mandatory)] - [string]$ActionName, - - [Parameter(Mandatory)] - [int]$PercentComplete, - - [Parameter(Mandatory)] - [scriptblock]$UpdateCommand - ) - - if (Test-PSPreworkoutCommand -Name $CommandName) { - Write-Host $DisplayName - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = $CurrentOperation - Status = "Progress: $PercentComplete`% Complete" - PercentComplete = $PercentComplete - } - Write-Progress @ProgressParamOuter - if ($PSCmdlet.ShouldProcess($TargetName, $ActionName)) { - & $UpdateCommand - } - } else { - Write-Verbose "$DisplayName was skipped because $CommandName was not found." - } - } - - #region UpdatePowerShell - - # ==================== Update PowerShell Modules ==================== - - # Update the outer progress bar - $PercentCompleteOuter = 1 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Getting Installed PowerShell Modules' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - - if (-not $SkipModules) { - # Get all installed PowerShell modules - Write-Host '[1] Getting Installed PowerShell Modules' - $Modules = (Get-InstalledModule) - $ModuleCount = $Modules.Count - Write-Host "[2] Updating $ModuleCount PowerShell Modules" - } else { - Write-Host '[1] Skipping PowerShell Modules' - } - - # Estimate 10% progress so far and 70% at the next step - $PercentCompleteOuter_Modules = 10 - [int]$Module_i = 0 - - # Update all PowerShell modules - foreach ($module in $Modules) { - # Update the module loop counter and percent complete for both progress bars - ++$Module_i - [double]$PercentCompleteInner = [math]::ceiling( (($Module_i / $ModuleCount) * 100) ) - [double]$PercentCompleteOuter = [math]::ceiling( $PercentCompleteOuter_Modules + (60 * ($PercentCompleteInner / 100)) ) - - # Update the outer progress bar while updating modules - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - - # Update the child progress bar while updating modules - $ProgressParam1 = @{ - Id = 1 - ParentId = 0 - Activity = 'Updating PowerShell Modules' - CurrentOperation = "$($module.Name)" - Status = "Progress: $PercentCompleteInner`% Complete" - PercentComplete = $PercentCompleteInner - } - Write-Progress @ProgressParam1 - - # Do not update prerelease modules - if ($module.Version -match 'alpha|beta|prerelease|preview') { - Write-Information "`t`tSkipping $($module.Name) because a prerelease version is currently installed." -InformationAction Continue - continue - } - - # Finally update the current module - try { - if ($PSCmdlet.ShouldProcess($module.Name, 'Update PowerShell module')) { - Update-Module $module.Name - } - } catch [Microsoft.PowerShell.Commands.WriteErrorException] { - # Add a catch for mismatched certificates between module versions. - Write-Verbose $_ + $CommonParameters = @{} + foreach ($CommonParameterName in 'WhatIf', 'Confirm') { + if ($PSBoundParameters.ContainsKey($CommonParameterName)) { + $CommonParameters[$CommonParameterName] = $PSBoundParameters[$CommonParameterName] } } - # ##### Add a section for installed scripts +++++ - if (-not $SkipScripts) { - Write-Host '[2] Updating PowerShell Scripts' - if ($PSCmdlet.ShouldProcess('Installed PowerShell scripts', 'Update scripts')) { - Update-Script - } - } else { - Write-Host '[2] Skipping PowerShell Scripts' - } - # ##### Add a section for installed scripts +++++ - - # Complete the child progress bar after updating modules - Write-Progress -Id 1 -Activity 'Updating PowerShell Modules' -Completed - + $Platform = Get-PSPreworkoutPlatform - # ==================== Update PowerShell Help ==================== + Set-UpdateRepositoryTrust @CommonParameters + Update-PowerShellArtifact -SkipModules:$SkipModules -SkipScripts:$SkipScripts -SkipHelp:$SkipHelp @CommonParameters - # Update the outer progress bar while updating help - $PercentCompleteOuter = 70 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating PowerShell Help' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - - if (-not $SkipHelp) { - Write-Host '[3] Updating PowerShell Help' - # Fixes error with culture ID 127 (Invariant Country), which is not associated with any language - if ($PSCmdlet.ShouldProcess('PowerShell help files', 'Update help')) { - if ((Get-Culture).LCID -eq 127) { - Update-Help -UICulture en-US -ErrorAction SilentlyContinue - } else { - Update-Help -ErrorAction SilentlyContinue - } - } - } else { - Write-Host '[3] Skipping PowerShell Help' - } - #endregion UpdatePowerShell - - #region UpdateWinget - # >>> Create a section to check OS and client/server OS at the top of the script <<< # if ($Platform -eq 'Windows') { - $WinGetAvailable = Test-PSPreworkoutCommand -Name 'winget' - $WindowsOsCaption = $null - $ShouldUpdateWinGet = $false - $SkipServerPrompt = $AcceptPrompts -or $WhatIfPreference -or ($PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm)) - $ShouldProcessHandlesConsent = ($PSBoundParameters.ContainsKey('Confirm') -and $Confirm) -or ( - ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and - (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) - ) - $NeedServerPrompt = $WinGetAvailable -and (-not $SkipWinGet) -and (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) - - if ($WinGetAvailable -and (-not $SkipWinGet)) { - $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') - } - - if ($NeedServerPrompt) { - $WindowsOsCaption = Get-WindowsOperatingSystemCaption - - if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { - Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' - $SkipWinGet = $true - $ShouldUpdateWinGet = $false - } - } - - if ($ShouldUpdateWinGet -and $NeedServerPrompt -and ($WindowsOsCaption -match 'Server')) { - # If on Windows Server, prompt to continue before automatically updating packages. - Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' - - $Result = Read-WinGetServerChoice - switch ($Result) { - 0 { - Write-Verbose 'Continuing with WinGet package updates.' - } - 1 { - $SkipWinGet = $true - $ShouldUpdateWinGet = $false - } - } - } - - if (-not $SkipWinGet) { - if ($WinGetAvailable) { - if ($ShouldUpdateWinGet -or $WhatIfPreference) { - # Update all winget packages - Write-Host '[4] Updating Winget Packages' - # Update the outer progress bar for winget section - $PercentCompleteOuter = 80 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating Winget Packages' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - } - if ($ShouldUpdateWinGet) { - Invoke-WinGetUpgrade - } - } else { - Write-Host '[4] WinGet was not found. Skipping WinGet update.' - } - } else { - Write-Host '[4] Skipping WinGet' - } + Update-WinGetPackage -Skip:$SkipWinGet -AcceptPrompts:$AcceptPrompts @CommonParameters } else { Write-Verbose '[4] Not Windows. Skipping WinGet.' } - #endregion UpdateWinget - #region UpdateLinuxPackages - # Early testing. No progress bar yet. Need to check for admin, different distros, and different package managers. if ($Platform -eq 'Linux') { - # Determine if we need sudo (not needed if already root) - $NeedsSudo = -not (Test-IsElevated) - - if (Test-PSPreworkoutCommand -Name 'apt') { - Write-Host '[5] Updating apt packages.' - if ($PSCmdlet.ShouldProcess('apt packages', 'Update and upgrade packages')) { - if ($NeedsSudo) { - & sudo apt update - if ($AcceptPrompts) { - & sudo apt upgrade -y - } else { - & sudo apt upgrade - } - } else { - & apt update - if ($AcceptPrompts) { - & apt upgrade -y - } else { - & apt upgrade - } - } - } - } - if (Test-PSPreworkoutCommand -Name 'dnf') { - Write-Host '[5] Updating dnf packages.' - if ($PSCmdlet.ShouldProcess('dnf packages', 'Update packages')) { - if ($NeedsSudo) { - if ($AcceptPrompts) { - & sudo dnf update -y - } else { - & sudo dnf update - } - } else { - if ($AcceptPrompts) { - & dnf update -y - } else { - & dnf update - } - } - } - } + Update-LinuxPackage -AcceptPrompts:$AcceptPrompts @CommonParameters } else { Write-Verbose '[5] Not Linux. Skipping section.' } - #endregion UpdateLinuxPackages - #region UpdateMacOS - # Early testing. No progress bar yet. Need to check for admin and different package managers. if ($Platform -eq 'macOS') { - if ($PSCmdlet.ShouldProcess('macOS software updates', 'List available updates')) { - softwareupdate -l - } - if (Test-PSPreworkoutCommand -Name 'brew') { - Write-Host '[6] Updating brew packages.' - if ($PSCmdlet.ShouldProcess('Homebrew packages', 'Update and upgrade packages')) { - brew update - brew upgrade - } - } + Update-MacOSPackage @CommonParameters } else { Write-Verbose '[6] Not macOS. Skipping section.' } - #endregion UpdateMacOS $OptionalCliUpdates = @( @{ @@ -799,9 +1036,7 @@ function Update-AllTheThings { TargetName = 'GitHub CLI extensions' ActionName = 'Upgrade all installed extensions' PercentComplete = 90 - UpdateCommand = { - Invoke-GitHubCliExtensionUpgrade - } + UpdateCommand = { Invoke-GitHubCliExtensionUpgrade } } @{ CommandName = 'copilot' @@ -810,67 +1045,20 @@ function Update-AllTheThings { TargetName = 'GitHub Copilot CLI' ActionName = 'Update installed CLI' PercentComplete = 95 - UpdateCommand = { - Invoke-GitHubCopilotCliUpdate - } + UpdateCommand = { Invoke-GitHubCopilotCliUpdate } } ) foreach ($CliUpdate in $OptionalCliUpdates) { - & $InvokeOptionalCliUpdate @CliUpdate - } - - #region UpdateChocolatey - # Upgrade Chocolatey packages. Need to check for admin to avoid errors/warnings. - if ((Test-PSPreworkoutCommand -Name 'choco') -and $IncludeChocolatey) { - # Update the outer progress bar - $PercentCompleteOuter = 98 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating Chocolatey Packages' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - Write-Host '[9] Updating Chocolatey Packages' - # Add a function/parameter to run these two feature configuration options, which requires admin to set. - if (Test-IsElevated) { - # Oops, this depends on PSPreworkout being installed or that function otherwise being available. - if ($PSCmdlet.ShouldProcess('Chocolatey features', 'Enable global confirmation and disable non-elevated warnings')) { - choco feature enable -n=allowGlobalConfirmation - choco feature disable --name=showNonElevatedWarnings - } - } else { - Write-Verbose "Run once as an administrator to disable Chocolatey's showNonElevatedWarnings." -Verbose - } - if ($PSCmdlet.ShouldProcess('Chocolatey packages', 'Upgrade Chocolatey and all packages')) { - choco upgrade chocolatey -y --limit-output --accept-license --no-color - choco upgrade all -y --limit-output --accept-license --no-color - } - # Padding to reset host before updating the progress bar. - Write-Host ' ' - } else { - Write-Host '[9] Skipping Chocolatey' + Update-OptionalCli @CliUpdate @CommonParameters } - #endregion UpdateChocolatey - } # end process block + Update-ChocolateyPackage -Include:$IncludeChocolatey @CommonParameters + } end { Write-Host 'Done.' - # Update the outer progress bar - $PercentCompleteOuter = 100 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Finished' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - # Complete the outer progress bar - Write-Progress -Id 0 -Activity 'Update Everything' -Completed + Write-UpdateAllTheThingsProgress -CurrentOperation 'Finished' -PercentComplete 100 + Write-UpdateAllTheThingsProgress -Completed } - } diff --git a/Scripts/Update-AllTheThings_Build.ps1 b/Scripts/Update-AllTheThings_Build.ps1 index 01361ccc..ce9faee5 100644 --- a/Scripts/Update-AllTheThings_Build.ps1 +++ b/Scripts/Update-AllTheThings_Build.ps1 @@ -41,6 +41,8 @@ if (-not $PSBoundParameters.ContainsKey('OutputPath')) { $SourcePaths = @( (Join-Path -Path $ModuleRoot -ChildPath 'Private\Test-PSPreworkoutCommand.ps1') (Join-Path -Path $ModuleRoot -ChildPath 'Private\Get-PSPreworkoutPlatform.ps1') + (Join-Path -Path $ModuleRoot -ChildPath 'Private\Write-UpdateAllTheThingsProgress.ps1') + (Join-Path -Path $ModuleRoot -ChildPath 'Private\Invoke-UpdateNativeCommand.ps1') (Join-Path -Path $ModuleRoot -ChildPath 'Private\Get-CimOperatingSystemCaption.ps1') (Join-Path -Path $ModuleRoot -ChildPath 'Private\Get-WmiOperatingSystemCaption.ps1') (Join-Path -Path $ModuleRoot -ChildPath 'Private\Get-WindowsOperatingSystemCaption.ps1') @@ -48,6 +50,13 @@ $SourcePaths = @( (Join-Path -Path $ModuleRoot -ChildPath 'Private\Invoke-WinGetUpgrade.ps1') (Join-Path -Path $ModuleRoot -ChildPath 'Private\Invoke-GitHubCliExtensionUpgrade.ps1') (Join-Path -Path $ModuleRoot -ChildPath 'Private\Invoke-GitHubCopilotCliUpdate.ps1') + (Join-Path -Path $ModuleRoot -ChildPath 'Private\Set-UpdateRepositoryTrust.ps1') + (Join-Path -Path $ModuleRoot -ChildPath 'Private\Update-PowerShellArtifact.ps1') + (Join-Path -Path $ModuleRoot -ChildPath 'Private\Update-WinGetPackage.ps1') + (Join-Path -Path $ModuleRoot -ChildPath 'Private\Update-LinuxPackage.ps1') + (Join-Path -Path $ModuleRoot -ChildPath 'Private\Update-MacOSPackage.ps1') + (Join-Path -Path $ModuleRoot -ChildPath 'Private\Update-OptionalCli.ps1') + (Join-Path -Path $ModuleRoot -ChildPath 'Private\Update-ChocolateyPackage.ps1') (Join-Path -Path $ModuleRoot -ChildPath 'Public\Test-IsElevated.ps1') $UpdateCommandPath ) diff --git a/Scripts/Update-AllTheThings_ScriptInfo.ps1 b/Scripts/Update-AllTheThings_ScriptInfo.ps1 index a62605e5..73cdfd9b 100644 --- a/Scripts/Update-AllTheThings_ScriptInfo.ps1 +++ b/Scripts/Update-AllTheThings_ScriptInfo.ps1 @@ -1,6 +1,6 @@ <#PSScriptInfo -.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, winget). -.VERSION 0.5.10 +.DESCRIPTION A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, WinGet). +.VERSION 0.6.0 .GUID 3a1a1ec9-0ef6-4f84-963d-be1505dab6a8 .AUTHOR Sam Erde .COPYRIGHT (c) 2024 Sam Erde. All rights reserved. diff --git a/docs/Update-AllTheThings.md b/docs/Update-AllTheThings.md index 43c59c31..72e1e41e 100644 --- a/docs/Update-AllTheThings.md +++ b/docs/Update-AllTheThings.md @@ -34,7 +34,7 @@ This cmdlet has the following aliases: A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, -Chocolatey, winget). +Chocolatey, WinGet). ## EXAMPLES @@ -185,7 +185,7 @@ HelpMessage: '' ### -SkipWinGet -Skip the step the updates WinGet packages. +Skip the step that updates WinGet packages. ```yaml Type: System.Management.Automation.SwitchParameter @@ -240,7 +240,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## NOTES Author: Sam Erde -Version: 0.5.10 +Version: 0.6.0 ## RELATED LINKS diff --git a/src/PSPreworkout/Private/Invoke-UpdateNativeCommand.ps1 b/src/PSPreworkout/Private/Invoke-UpdateNativeCommand.ps1 new file mode 100644 index 00000000..af2fd73c --- /dev/null +++ b/src/PSPreworkout/Private/Invoke-UpdateNativeCommand.ps1 @@ -0,0 +1,54 @@ +function Invoke-UpdateNativeCommand { + <# + .SYNOPSIS + Invokes a native update command and validates its exit code. + + .DESCRIPTION + Provides consistent invocation and explicit failure handling for native + package-manager commands. + + .PARAMETER Name + The native command to invoke. + + .PARAMETER ArgumentList + Arguments passed to the native command. + + .PARAMETER FailureMessage + Context included in the terminating error when the command fails. + + .PARAMETER Command + An invocation seam used by unit tests. + + .OUTPUTS + None + #> + + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$Name, + + [Parameter()] + [AllowEmptyCollection()] + [string[]]$ArgumentList = @(), + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$FailureMessage, + + [Parameter(DontShow)] + [ValidateNotNull()] + [scriptblock]$Command = { + param($CommandName, $CommandArguments) + + & $CommandName @CommandArguments | Out-Host + return $LASTEXITCODE + } + ) + + $ExitCode = & $Command $Name $ArgumentList + if ($ExitCode -ne 0) { + throw "$FailureMessage failed with exit code $ExitCode." + } +} diff --git a/src/PSPreworkout/Private/Set-UpdateRepositoryTrust.ps1 b/src/PSPreworkout/Private/Set-UpdateRepositoryTrust.ps1 new file mode 100644 index 00000000..4a7a520f --- /dev/null +++ b/src/PSPreworkout/Private/Set-UpdateRepositoryTrust.ps1 @@ -0,0 +1,32 @@ +function Set-UpdateRepositoryTrust { + <# + .SYNOPSIS + Trusts supported PowerShell Gallery repositories. + + .DESCRIPTION + Configures PSGallery as trusted for the installed PowerShellGet and + PSResourceGet clients. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param() + + Write-Verbose 'Set the PowerShell Gallery as a trusted installation source.' + + if ( + (Test-PSPreworkoutCommand -Name 'Set-PSRepository') -and + $PSCmdlet.ShouldProcess('PSGallery', 'Set PowerShellGet repository as trusted') + ) { + Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted + } + + if ( + (Test-PSPreworkoutCommand -Name 'Set-PSResourceRepository') -and + $PSCmdlet.ShouldProcess('PSGallery', 'Set PSResourceGet repository as trusted') + ) { + Set-PSResourceRepository -Name 'PSGallery' -Trusted + } +} diff --git a/src/PSPreworkout/Private/Update-ChocolateyPackage.ps1 b/src/PSPreworkout/Private/Update-ChocolateyPackage.ps1 new file mode 100644 index 00000000..6aa005ee --- /dev/null +++ b/src/PSPreworkout/Private/Update-ChocolateyPackage.ps1 @@ -0,0 +1,53 @@ +function Update-ChocolateyPackage { + <# + .SYNOPSIS + Updates Chocolatey and installed Chocolatey packages. + + .DESCRIPTION + Optionally configures Chocolatey features when elevated, then updates + Chocolatey and all installed packages. + + .PARAMETER Include + Enables Chocolatey package updates. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter()] + [switch]$Include + ) + + if ((-not $Include) -or (-not (Test-PSPreworkoutCommand -Name 'choco'))) { + Write-Information '[9] Skipping Chocolatey' -InformationAction Continue + return + } + + Write-UpdateAllTheThingsProgress -CurrentOperation 'Updating Chocolatey Packages' -PercentComplete 98 + Write-Information '[9] Updating Chocolatey Packages' -InformationAction Continue + + if (Test-IsElevated) { + if ($PSCmdlet.ShouldProcess('Chocolatey features', 'Enable global confirmation and disable non-elevated warnings')) { + Invoke-UpdateNativeCommand -Name 'choco' -ArgumentList @( + 'feature', 'enable', '-n=allowGlobalConfirmation' + ) -FailureMessage 'Chocolatey global confirmation configuration' + Invoke-UpdateNativeCommand -Name 'choco' -ArgumentList @( + 'feature', 'disable', '--name=showNonElevatedWarnings' + ) -FailureMessage 'Chocolatey non-elevated warning configuration' + } + } else { + Write-Verbose "Run once as an administrator to disable Chocolatey's showNonElevatedWarnings." -Verbose + } + + if ($PSCmdlet.ShouldProcess('Chocolatey packages', 'Upgrade Chocolatey and all packages')) { + $UpgradeArguments = @('-y', '--limit-output', '--accept-license', '--no-color') + $SelfUpdateArguments = @('upgrade', 'chocolatey') + $UpgradeArguments + $PackageUpdateArguments = @('upgrade', 'all') + $UpgradeArguments + Invoke-UpdateNativeCommand -Name 'choco' -ArgumentList $SelfUpdateArguments -FailureMessage 'Chocolatey self-update' + Invoke-UpdateNativeCommand -Name 'choco' -ArgumentList $PackageUpdateArguments -FailureMessage 'Chocolatey package update' + } + + Write-Information ' ' -InformationAction Continue +} diff --git a/src/PSPreworkout/Private/Update-LinuxPackage.ps1 b/src/PSPreworkout/Private/Update-LinuxPackage.ps1 new file mode 100644 index 00000000..deeabdd8 --- /dev/null +++ b/src/PSPreworkout/Private/Update-LinuxPackage.ps1 @@ -0,0 +1,58 @@ +function Update-LinuxPackage { + <# + .SYNOPSIS + Updates packages with supported Linux package managers. + + .DESCRIPTION + Updates apt and dnf packages, using sudo only when the current process is + not elevated. + + .PARAMETER AcceptPrompts + Passes the non-interactive acceptance argument to package managers. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter()] + [switch]$AcceptPrompts + ) + + $AptAvailable = Test-PSPreworkoutCommand -Name 'apt' + $DnfAvailable = Test-PSPreworkoutCommand -Name 'dnf' + if ((-not $AptAvailable) -and (-not $DnfAvailable)) { + return + } + + $NeedsSudo = -not (Test-IsElevated) + + if ($AptAvailable) { + Write-Information '[5] Updating apt packages.' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('apt packages', 'Update and upgrade packages')) { + $CommandName = if ($NeedsSudo) { 'sudo' } else { 'apt' } + $UpdateArguments = if ($NeedsSudo) { @('apt', 'update') } else { @('update') } + [string[]]$UpgradeArguments = if ($NeedsSudo) { @('apt', 'upgrade') } else { @('upgrade') } + if ($AcceptPrompts) { + $UpgradeArguments += '-y' + } + + Invoke-UpdateNativeCommand -Name $CommandName -ArgumentList $UpdateArguments -FailureMessage 'apt package index update' + Invoke-UpdateNativeCommand -Name $CommandName -ArgumentList $UpgradeArguments -FailureMessage 'apt package upgrade' + } + } + + if ($DnfAvailable) { + Write-Information '[5] Updating dnf packages.' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('dnf packages', 'Update packages')) { + $CommandName = if ($NeedsSudo) { 'sudo' } else { 'dnf' } + [string[]]$Arguments = if ($NeedsSudo) { @('dnf', 'update') } else { @('update') } + if ($AcceptPrompts) { + $Arguments += '-y' + } + + Invoke-UpdateNativeCommand -Name $CommandName -ArgumentList $Arguments -FailureMessage 'dnf package update' + } + } +} diff --git a/src/PSPreworkout/Private/Update-MacOSPackage.ps1 b/src/PSPreworkout/Private/Update-MacOSPackage.ps1 new file mode 100644 index 00000000..e5f4c00c --- /dev/null +++ b/src/PSPreworkout/Private/Update-MacOSPackage.ps1 @@ -0,0 +1,28 @@ +function Update-MacOSPackage { + <# + .SYNOPSIS + Updates supported macOS software. + + .DESCRIPTION + Lists macOS software updates and updates Homebrew packages when Homebrew is + installed. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param() + + if ($PSCmdlet.ShouldProcess('macOS software updates', 'List available updates')) { + Invoke-UpdateNativeCommand -Name 'softwareupdate' -ArgumentList '-l' -FailureMessage 'macOS software update query' + } + + if (Test-PSPreworkoutCommand -Name 'brew') { + Write-Information '[6] Updating brew packages.' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('Homebrew packages', 'Update and upgrade packages')) { + Invoke-UpdateNativeCommand -Name 'brew' -ArgumentList 'update' -FailureMessage 'Homebrew update' + Invoke-UpdateNativeCommand -Name 'brew' -ArgumentList 'upgrade' -FailureMessage 'Homebrew upgrade' + } + } +} diff --git a/src/PSPreworkout/Private/Update-OptionalCli.ps1 b/src/PSPreworkout/Private/Update-OptionalCli.ps1 new file mode 100644 index 00000000..5d3716ba --- /dev/null +++ b/src/PSPreworkout/Private/Update-OptionalCli.ps1 @@ -0,0 +1,75 @@ +function Update-OptionalCli { + <# + .SYNOPSIS + Updates an optional command-line tool. + + .DESCRIPTION + Runs a supplied update command when its command-line tool is installed. + + .PARAMETER CommandName + The command used to detect whether the tool is installed. + + .PARAMETER DisplayName + The status text displayed to the user. + + .PARAMETER CurrentOperation + The operation shown in the progress record. + + .PARAMETER TargetName + The ShouldProcess target. + + .PARAMETER ActionName + The ShouldProcess action. + + .PARAMETER PercentComplete + The overall completion percentage. + + .PARAMETER UpdateCommand + The update operation to invoke. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$CommandName, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$DisplayName, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$CurrentOperation, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$TargetName, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$ActionName, + + [Parameter(Mandatory)] + [ValidateRange(0, 100)] + [int]$PercentComplete, + + [Parameter(Mandatory)] + [ValidateNotNull()] + [scriptblock]$UpdateCommand + ) + + if (-not (Test-PSPreworkoutCommand -Name $CommandName)) { + Write-Verbose "$DisplayName was skipped because $CommandName was not found." + return + } + + Write-Information $DisplayName -InformationAction Continue + Write-UpdateAllTheThingsProgress -CurrentOperation $CurrentOperation -PercentComplete $PercentComplete + if ($PSCmdlet.ShouldProcess($TargetName, $ActionName)) { + & $UpdateCommand + } +} diff --git a/src/PSPreworkout/Private/Update-PowerShellArtifact.ps1 b/src/PSPreworkout/Private/Update-PowerShellArtifact.ps1 new file mode 100644 index 00000000..7659ed28 --- /dev/null +++ b/src/PSPreworkout/Private/Update-PowerShellArtifact.ps1 @@ -0,0 +1,98 @@ +function Update-PowerShellArtifact { + <# + .SYNOPSIS + Updates installed PowerShell modules, scripts, and help. + + .DESCRIPTION + Handles PowerShell-native update operations and their progress reporting. + + .PARAMETER SkipModules + Skips installed module updates. + + .PARAMETER SkipScripts + Skips installed script updates. + + .PARAMETER SkipHelp + Skips PowerShell help updates. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter()] + [switch]$SkipModules, + + [Parameter()] + [switch]$SkipScripts, + + [Parameter()] + [switch]$SkipHelp + ) + + Write-UpdateAllTheThingsProgress -CurrentOperation 'Getting Installed PowerShell Modules' -PercentComplete 1 + + if ($SkipModules) { + Write-Information '[1] Skipping PowerShell Modules' -InformationAction Continue + } elseif (-not (Test-PSPreworkoutCommand -Name 'Get-InstalledModule')) { + Write-Warning 'Get-InstalledModule was not found. Skipping PowerShell module updates.' + } else { + Write-Information '[1] Getting Installed PowerShell Modules' -InformationAction Continue + $Modules = @(Get-InstalledModule) + Write-Information "[2] Updating $($Modules.Count) PowerShell Modules" -InformationAction Continue + + $ModuleIndex = 0 + foreach ($Module in $Modules) { + ++$ModuleIndex + $ModulePercent = [math]::Ceiling(($ModuleIndex / $Modules.Count) * 100) + $OverallPercent = [math]::Ceiling(10 + (60 * ($ModulePercent / 100))) + + Write-UpdateAllTheThingsProgress -CurrentOperation "Updating PowerShell module $($Module.Name)" -PercentComplete $OverallPercent + Write-Progress -Id 1 -ParentId 0 -Activity 'Updating PowerShell Modules' ` + -CurrentOperation $Module.Name -Status "Progress: $ModulePercent`% Complete" ` + -PercentComplete $ModulePercent + + if ($Module.Version -match 'alpha|beta|prerelease|preview') { + Write-Information "`t`tSkipping $($Module.Name) because a prerelease version is currently installed." -InformationAction Continue + continue + } + + try { + if ($PSCmdlet.ShouldProcess($Module.Name, 'Update PowerShell module')) { + Update-Module -Name $Module.Name + } + } catch [Microsoft.PowerShell.Commands.WriteErrorException] { + Write-Warning "Unable to update PowerShell module '$($Module.Name)': $($_.Exception.Message)" + } + } + } + + Write-Progress -Id 1 -Activity 'Updating PowerShell Modules' -Completed + + if ($SkipScripts) { + Write-Information '[2] Skipping PowerShell Scripts' -InformationAction Continue + } elseif (-not (Test-PSPreworkoutCommand -Name 'Update-Script')) { + Write-Warning 'Update-Script was not found. Skipping PowerShell script updates.' + } else { + Write-Information '[2] Updating PowerShell Scripts' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('Installed PowerShell scripts', 'Update scripts')) { + Update-Script + } + } + + Write-UpdateAllTheThingsProgress -CurrentOperation 'Updating PowerShell Help' -PercentComplete 70 + + if ($SkipHelp) { + Write-Information '[3] Skipping PowerShell Help' -InformationAction Continue + } else { + Write-Information '[3] Updating PowerShell Help' -InformationAction Continue + if ($PSCmdlet.ShouldProcess('PowerShell help files', 'Update help')) { + if ((Get-Culture).LCID -eq 127) { + Update-Help -UICulture en-US -ErrorAction SilentlyContinue + } else { + Update-Help -ErrorAction SilentlyContinue + } + } + } +} diff --git a/src/PSPreworkout/Private/Update-WinGetPackage.ps1 b/src/PSPreworkout/Private/Update-WinGetPackage.ps1 new file mode 100644 index 00000000..5bfd03f1 --- /dev/null +++ b/src/PSPreworkout/Private/Update-WinGetPackage.ps1 @@ -0,0 +1,72 @@ +function Update-WinGetPackage { + <# + .SYNOPSIS + Updates user-scoped WinGet packages. + + .DESCRIPTION + Applies Windows Server safeguards before invoking WinGet. + + .PARAMETER Skip + Skips WinGet package updates. + + .PARAMETER AcceptPrompts + Bypasses the additional Windows Server confirmation prompt. + + .OUTPUTS + None + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + param( + [Parameter()] + [switch]$Skip, + + [Parameter()] + [switch]$AcceptPrompts + ) + + if ($Skip) { + Write-Information '[4] Skipping WinGet' -InformationAction Continue + return + } + + if (-not (Test-PSPreworkoutCommand -Name 'winget')) { + Write-Information '[4] WinGet was not found. Skipping WinGet update.' -InformationAction Continue + return + } + + $ShouldUpdate = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') + $SkipServerPrompt = $AcceptPrompts -or $WhatIfPreference -or ( + $PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm) + ) + $ShouldProcessHandlesConsent = ($PSBoundParameters.ContainsKey('Confirm') -and $Confirm) -or ( + ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and + (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) + ) + $NeedServerPrompt = (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) + + if ($NeedServerPrompt) { + $WindowsOsCaption = Get-WindowsOperatingSystemCaption + if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { + Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' + return + } + + if ($ShouldUpdate -and ($WindowsOsCaption -match 'Server')) { + Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' + if ((Read-WinGetServerChoice) -ne 0) { + return + } + Write-Verbose 'Continuing with WinGet package updates.' + } + } + + if ($ShouldUpdate -or $WhatIfPreference) { + Write-Information '[4] Updating WinGet Packages' -InformationAction Continue + Write-UpdateAllTheThingsProgress -CurrentOperation 'Updating WinGet Packages' -PercentComplete 80 + } + + if ($ShouldUpdate) { + Invoke-WinGetUpgrade + } +} diff --git a/src/PSPreworkout/Private/Write-UpdateAllTheThingsProgress.ps1 b/src/PSPreworkout/Private/Write-UpdateAllTheThingsProgress.ps1 new file mode 100644 index 00000000..964fee4c --- /dev/null +++ b/src/PSPreworkout/Private/Write-UpdateAllTheThingsProgress.ps1 @@ -0,0 +1,50 @@ +function Write-UpdateAllTheThingsProgress { + <# + .SYNOPSIS + Writes progress for Update-AllTheThings. + + .DESCRIPTION + Centralizes the parent progress record used by Update-AllTheThings and its + private update helpers. + + .PARAMETER CurrentOperation + The operation currently being performed. + + .PARAMETER PercentComplete + The percentage of the overall update that is complete. + + .PARAMETER Completed + Completes and removes the progress record. + + .OUTPUTS + None + #> + + [CmdletBinding()] + param( + [Parameter()] + [ValidateNotNullOrEmpty()] + [string]$CurrentOperation, + + [Parameter()] + [ValidateRange(0, 100)] + [int]$PercentComplete = 0, + + [Parameter()] + [switch]$Completed + ) + + if ($Completed) { + Write-Progress -Id 0 -Activity 'Update Everything' -Completed + return + } + + $ProgressParameters = @{ + Id = 0 + Activity = 'Update Everything' + CurrentOperation = $CurrentOperation + Status = "Progress: $PercentComplete`% Complete" + PercentComplete = $PercentComplete + } + Write-Progress @ProgressParameters +} diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index d9106867..210636e0 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -4,7 +4,7 @@ function Update-AllTheThings { Update all the things! .DESCRIPTION - A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, winget). + A script to automatically update all PowerShell modules, PowerShell Help, GitHub CLI extensions, GitHub Copilot CLI, and packages (apt, brew, Chocolatey, WinGet). .PARAMETER SkipModules Skip the step that updates PowerShell modules. @@ -16,7 +16,7 @@ function Update-AllTheThings { Skip the step that updates PowerShell help. .PARAMETER SkipWinGet - Skip the step the updates WinGet packages. + Skip the step that updates WinGet packages. .PARAMETER IncludeChocolatey Include Chocolatey package updates. @@ -36,7 +36,7 @@ function Update-AllTheThings { .NOTES Author: Sam Erde - Version: 0.5.10 + Version: 0.6.0 #> [CmdletBinding( @@ -50,43 +50,35 @@ function Update-AllTheThings { param ( # Skip the step that updates PowerShell modules [Parameter()] - [switch] - $SkipModules, + [switch]$SkipModules, # Skip the step that updates PowerShell scripts [Parameter()] - [switch] - $SkipScripts, + [switch]$SkipScripts, # Skip the step that updates PowerShell help [Parameter()] - [switch] - $SkipHelp, + [switch]$SkipHelp, # Skip the step that updates WinGet packages [Parameter()] - [switch] - $SkipWinGet, + [switch]$SkipWinGet, - # Skip the step that updates Chocolatey packages + # Include Chocolatey package updates [Parameter()] [Alias('SkipChoco')] - [switch] - $IncludeChocolatey, + [switch]$IncludeChocolatey, - # Automatically accept prompts to install updates in Linux + # Automatically accept prompts to install updates [Parameter()] - [switch] - $AcceptPrompts + [switch]$AcceptPrompts ) begin { - # Send non-identifying usage statistics to PostHog when the helper is available. if (Test-PSPreworkoutCommand -Name 'Write-PSPreworkoutTelemetry') { Write-PSPreworkoutTelemetry -EventName $MyInvocation.MyCommand.Name -ParameterNamesOnly $MyInvocation.BoundParameters.Keys } - # Spacing to get host output from script, winget, and choco all below the progress bar. $Banner = @" __ __ __ __ ___ ____ / / / /__ ___/ /__ _/ /____ / _ | / / / @@ -96,325 +88,42 @@ function Update-AllTheThings { /_ __/ / ___ /_ __/ / (_)__ ___ ____ / / / _ \/ -_) / / / _ \/ / _ \/ _ `(_-< /_/ /_//_/\__/ /_/ /_//_/_/_//_/\_, /___/ - /___/ v0.5.10 + /___/ v0.6.0 "@ Write-Host $Banner - } # end begin block + } process { - $Platform = Get-PSPreworkoutPlatform - - Write-Verbose 'Set the PowerShell Gallery as a trusted installation source.' - if ( - (Test-PSPreworkoutCommand -Name 'Set-PSRepository') -and - $PSCmdlet.ShouldProcess('PSGallery', 'Set PowerShellGet repository as trusted') - ) { - Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted - } - if (Test-PSPreworkoutCommand -Name 'Set-PSResourceRepository') { - if ($PSCmdlet.ShouldProcess('PSGallery', 'Set PSResourceGet repository as trusted')) { - Set-PSResourceRepository -Name 'PSGallery' -Trusted - } - } - - $InvokeOptionalCliUpdate = { - param( - [Parameter(Mandatory)] - [string]$CommandName, - - [Parameter(Mandatory)] - [string]$DisplayName, - - [Parameter(Mandatory)] - [string]$CurrentOperation, - - [Parameter(Mandatory)] - [string]$TargetName, - - [Parameter(Mandatory)] - [string]$ActionName, - - [Parameter(Mandatory)] - [int]$PercentComplete, - - [Parameter(Mandatory)] - [scriptblock]$UpdateCommand - ) - - if (Test-PSPreworkoutCommand -Name $CommandName) { - Write-Host $DisplayName - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = $CurrentOperation - Status = "Progress: $PercentComplete`% Complete" - PercentComplete = $PercentComplete - } - Write-Progress @ProgressParamOuter - if ($PSCmdlet.ShouldProcess($TargetName, $ActionName)) { - & $UpdateCommand - } - } else { - Write-Verbose "$DisplayName was skipped because $CommandName was not found." - } - } - - #region UpdatePowerShell - - # ==================== Update PowerShell Modules ==================== - - # Update the outer progress bar - $PercentCompleteOuter = 1 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Getting Installed PowerShell Modules' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - - if (-not $SkipModules) { - # Get all installed PowerShell modules - Write-Host '[1] Getting Installed PowerShell Modules' - $Modules = (Get-InstalledModule) - $ModuleCount = $Modules.Count - Write-Host "[2] Updating $ModuleCount PowerShell Modules" - } else { - Write-Host '[1] Skipping PowerShell Modules' - } - - # Estimate 10% progress so far and 70% at the next step - $PercentCompleteOuter_Modules = 10 - [int]$Module_i = 0 - - # Update all PowerShell modules - foreach ($module in $Modules) { - # Update the module loop counter and percent complete for both progress bars - ++$Module_i - [double]$PercentCompleteInner = [math]::ceiling( (($Module_i / $ModuleCount) * 100) ) - [double]$PercentCompleteOuter = [math]::ceiling( $PercentCompleteOuter_Modules + (60 * ($PercentCompleteInner / 100)) ) - - # Update the outer progress bar while updating modules - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - - # Update the child progress bar while updating modules - $ProgressParam1 = @{ - Id = 1 - ParentId = 0 - Activity = 'Updating PowerShell Modules' - CurrentOperation = "$($module.Name)" - Status = "Progress: $PercentCompleteInner`% Complete" - PercentComplete = $PercentCompleteInner - } - Write-Progress @ProgressParam1 - - # Do not update prerelease modules - if ($module.Version -match 'alpha|beta|prerelease|preview') { - Write-Information "`t`tSkipping $($module.Name) because a prerelease version is currently installed." -InformationAction Continue - continue - } - - # Finally update the current module - try { - if ($PSCmdlet.ShouldProcess($module.Name, 'Update PowerShell module')) { - Update-Module $module.Name - } - } catch [Microsoft.PowerShell.Commands.WriteErrorException] { - # Add a catch for mismatched certificates between module versions. - Write-Verbose $_ - } - } - - # ##### Add a section for installed scripts +++++ - if (-not $SkipScripts) { - Write-Host '[2] Updating PowerShell Scripts' - if ($PSCmdlet.ShouldProcess('Installed PowerShell scripts', 'Update scripts')) { - Update-Script + $CommonParameters = @{} + foreach ($CommonParameterName in 'WhatIf', 'Confirm') { + if ($PSBoundParameters.ContainsKey($CommonParameterName)) { + $CommonParameters[$CommonParameterName] = $PSBoundParameters[$CommonParameterName] } - } else { - Write-Host '[2] Skipping PowerShell Scripts' } - # ##### Add a section for installed scripts +++++ - - # Complete the child progress bar after updating modules - Write-Progress -Id 1 -Activity 'Updating PowerShell Modules' -Completed + $Platform = Get-PSPreworkoutPlatform - # ==================== Update PowerShell Help ==================== + Set-UpdateRepositoryTrust @CommonParameters + Update-PowerShellArtifact -SkipModules:$SkipModules -SkipScripts:$SkipScripts -SkipHelp:$SkipHelp @CommonParameters - # Update the outer progress bar while updating help - $PercentCompleteOuter = 70 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating PowerShell Help' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - - if (-not $SkipHelp) { - Write-Host '[3] Updating PowerShell Help' - # Fixes error with culture ID 127 (Invariant Country), which is not associated with any language - if ($PSCmdlet.ShouldProcess('PowerShell help files', 'Update help')) { - if ((Get-Culture).LCID -eq 127) { - Update-Help -UICulture en-US -ErrorAction SilentlyContinue - } else { - Update-Help -ErrorAction SilentlyContinue - } - } - } else { - Write-Host '[3] Skipping PowerShell Help' - } - #endregion UpdatePowerShell - - #region UpdateWinget - # >>> Create a section to check OS and client/server OS at the top of the script <<< # if ($Platform -eq 'Windows') { - $WinGetAvailable = Test-PSPreworkoutCommand -Name 'winget' - $WindowsOsCaption = $null - $ShouldUpdateWinGet = $false - $SkipServerPrompt = $AcceptPrompts -or $WhatIfPreference -or ($PSBoundParameters.ContainsKey('Confirm') -and (-not $Confirm)) - $ShouldProcessHandlesConsent = ($PSBoundParameters.ContainsKey('Confirm') -and $Confirm) -or ( - ($ConfirmPreference -ne [System.Management.Automation.ConfirmImpact]::None) -and - (([System.Management.Automation.ConfirmImpact]$ConfirmPreference) -le [System.Management.Automation.ConfirmImpact]::Medium) - ) - $NeedServerPrompt = $WinGetAvailable -and (-not $SkipWinGet) -and (-not $SkipServerPrompt) -and (-not $ShouldProcessHandlesConsent) - - if ($WinGetAvailable -and (-not $SkipWinGet)) { - $ShouldUpdateWinGet = $PSCmdlet.ShouldProcess('WinGet packages', 'Upgrade all user-scoped packages') - } - - if ($NeedServerPrompt) { - $WindowsOsCaption = Get-WindowsOperatingSystemCaption - - if ([string]::IsNullOrWhiteSpace($WindowsOsCaption)) { - Write-Warning -Message 'Unable to determine the Windows operating system caption. Skipping WinGet updates as a safety precaution.' - $SkipWinGet = $true - $ShouldUpdateWinGet = $false - } - } - - if ($ShouldUpdateWinGet -and $NeedServerPrompt -and ($WindowsOsCaption -match 'Server')) { - # If on Windows Server, prompt to continue before automatically updating packages. - Write-Warning -Message 'This is a server and updates could affect production systems. Do you want to continue with updating packages?' - - $Result = Read-WinGetServerChoice - switch ($Result) { - 0 { - Write-Verbose 'Continuing with WinGet package updates.' - } - 1 { - $SkipWinGet = $true - $ShouldUpdateWinGet = $false - } - } - } - - if (-not $SkipWinGet) { - if ($WinGetAvailable) { - if ($ShouldUpdateWinGet -or $WhatIfPreference) { - # Update all winget packages - Write-Host '[4] Updating Winget Packages' - # Update the outer progress bar for winget section - $PercentCompleteOuter = 80 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating Winget Packages' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - } - if ($ShouldUpdateWinGet) { - Invoke-WinGetUpgrade - } - } else { - Write-Host '[4] WinGet was not found. Skipping WinGet update.' - } - } else { - Write-Host '[4] Skipping WinGet' - } + Update-WinGetPackage -Skip:$SkipWinGet -AcceptPrompts:$AcceptPrompts @CommonParameters } else { Write-Verbose '[4] Not Windows. Skipping WinGet.' } - #endregion UpdateWinget - #region UpdateLinuxPackages - # Early testing. No progress bar yet. Need to check for admin, different distros, and different package managers. if ($Platform -eq 'Linux') { - # Determine if we need sudo (not needed if already root) - $NeedsSudo = -not (Test-IsElevated) - - if (Test-PSPreworkoutCommand -Name 'apt') { - Write-Host '[5] Updating apt packages.' - if ($PSCmdlet.ShouldProcess('apt packages', 'Update and upgrade packages')) { - if ($NeedsSudo) { - & sudo apt update - if ($AcceptPrompts) { - & sudo apt upgrade -y - } else { - & sudo apt upgrade - } - } else { - & apt update - if ($AcceptPrompts) { - & apt upgrade -y - } else { - & apt upgrade - } - } - } - } - if (Test-PSPreworkoutCommand -Name 'dnf') { - Write-Host '[5] Updating dnf packages.' - if ($PSCmdlet.ShouldProcess('dnf packages', 'Update packages')) { - if ($NeedsSudo) { - if ($AcceptPrompts) { - & sudo dnf update -y - } else { - & sudo dnf update - } - } else { - if ($AcceptPrompts) { - & dnf update -y - } else { - & dnf update - } - } - } - } + Update-LinuxPackage -AcceptPrompts:$AcceptPrompts @CommonParameters } else { Write-Verbose '[5] Not Linux. Skipping section.' } - #endregion UpdateLinuxPackages - #region UpdateMacOS - # Early testing. No progress bar yet. Need to check for admin and different package managers. if ($Platform -eq 'macOS') { - if ($PSCmdlet.ShouldProcess('macOS software updates', 'List available updates')) { - softwareupdate -l - } - if (Test-PSPreworkoutCommand -Name 'brew') { - Write-Host '[6] Updating brew packages.' - if ($PSCmdlet.ShouldProcess('Homebrew packages', 'Update and upgrade packages')) { - brew update - brew upgrade - } - } + Update-MacOSPackage @CommonParameters } else { Write-Verbose '[6] Not macOS. Skipping section.' } - #endregion UpdateMacOS $OptionalCliUpdates = @( @{ @@ -424,9 +133,7 @@ function Update-AllTheThings { TargetName = 'GitHub CLI extensions' ActionName = 'Upgrade all installed extensions' PercentComplete = 90 - UpdateCommand = { - Invoke-GitHubCliExtensionUpgrade - } + UpdateCommand = { Invoke-GitHubCliExtensionUpgrade } } @{ CommandName = 'copilot' @@ -435,67 +142,20 @@ function Update-AllTheThings { TargetName = 'GitHub Copilot CLI' ActionName = 'Update installed CLI' PercentComplete = 95 - UpdateCommand = { - Invoke-GitHubCopilotCliUpdate - } + UpdateCommand = { Invoke-GitHubCopilotCliUpdate } } ) foreach ($CliUpdate in $OptionalCliUpdates) { - & $InvokeOptionalCliUpdate @CliUpdate + Update-OptionalCli @CliUpdate @CommonParameters } - #region UpdateChocolatey - # Upgrade Chocolatey packages. Need to check for admin to avoid errors/warnings. - if ((Test-PSPreworkoutCommand -Name 'choco') -and $IncludeChocolatey) { - # Update the outer progress bar - $PercentCompleteOuter = 98 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Updating Chocolatey Packages' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - Write-Host '[9] Updating Chocolatey Packages' - # Add a function/parameter to run these two feature configuration options, which requires admin to set. - if (Test-IsElevated) { - # Oops, this depends on PSPreworkout being installed or that function otherwise being available. - if ($PSCmdlet.ShouldProcess('Chocolatey features', 'Enable global confirmation and disable non-elevated warnings')) { - choco feature enable -n=allowGlobalConfirmation - choco feature disable --name=showNonElevatedWarnings - } - } else { - Write-Verbose "Run once as an administrator to disable Chocolatey's showNonElevatedWarnings." -Verbose - } - if ($PSCmdlet.ShouldProcess('Chocolatey packages', 'Upgrade Chocolatey and all packages')) { - choco upgrade chocolatey -y --limit-output --accept-license --no-color - choco upgrade all -y --limit-output --accept-license --no-color - } - # Padding to reset host before updating the progress bar. - Write-Host ' ' - } else { - Write-Host '[9] Skipping Chocolatey' - } - #endregion UpdateChocolatey - - } # end process block + Update-ChocolateyPackage -Include:$IncludeChocolatey @CommonParameters + } end { Write-Host 'Done.' - # Update the outer progress bar - $PercentCompleteOuter = 100 - $ProgressParamOuter = @{ - Id = 0 - Activity = 'Update Everything' - CurrentOperation = 'Finished' - Status = "Progress: $PercentCompleteOuter`% Complete" - PercentComplete = $PercentCompleteOuter - } - Write-Progress @ProgressParamOuter - # Complete the outer progress bar - Write-Progress -Id 0 -Activity 'Update Everything' -Completed + Write-UpdateAllTheThingsProgress -CurrentOperation 'Finished' -PercentComplete 100 + Write-UpdateAllTheThingsProgress -Completed } - } diff --git a/src/Tests/Helpers/Update-AllTheThings.TestHelpers.ps1 b/src/Tests/Helpers/Update-AllTheThings.TestHelpers.ps1 index a51832b0..2c477c0f 100644 --- a/src/Tests/Helpers/Update-AllTheThings.TestHelpers.ps1 +++ b/src/Tests/Helpers/Update-AllTheThings.TestHelpers.ps1 @@ -5,6 +5,8 @@ $ModuleRoot = [System.IO.Path]::GetFullPath( $PrivatePaths = @( 'Test-PSPreworkoutCommand.ps1' 'Get-PSPreworkoutPlatform.ps1' + 'Write-UpdateAllTheThingsProgress.ps1' + 'Invoke-UpdateNativeCommand.ps1' 'Get-CimOperatingSystemCaption.ps1' 'Get-WmiOperatingSystemCaption.ps1' 'Get-WindowsOperatingSystemCaption.ps1' @@ -12,6 +14,13 @@ $PrivatePaths = @( 'Invoke-WinGetUpgrade.ps1' 'Invoke-GitHubCliExtensionUpgrade.ps1' 'Invoke-GitHubCopilotCliUpdate.ps1' + 'Set-UpdateRepositoryTrust.ps1' + 'Update-PowerShellArtifact.ps1' + 'Update-WinGetPackage.ps1' + 'Update-LinuxPackage.ps1' + 'Update-MacOSPackage.ps1' + 'Update-OptionalCli.ps1' + 'Update-ChocolateyPackage.ps1' 'Write-PSPreworkoutTelemetry.ps1' ) diff --git a/src/Tests/Invoke-UpdateAllTheThingsCompatibility.ps1 b/src/Tests/Invoke-UpdateAllTheThingsCompatibility.ps1 index 5dc3190e..b2f28698 100644 --- a/src/Tests/Invoke-UpdateAllTheThingsCompatibility.ps1 +++ b/src/Tests/Invoke-UpdateAllTheThingsCompatibility.ps1 @@ -30,6 +30,9 @@ $Configuration.Run.Path = @( (Join-Path -Path $PSScriptRoot -ChildPath 'Unit\Update-AllTheThings.Contract.Tests.ps1') (Join-Path -Path $PSScriptRoot -ChildPath 'Unit\Update-AllTheThings.Cli.Tests.ps1') (Join-Path -Path $PSScriptRoot -ChildPath 'Unit\Update-AllTheThings.WinGet.Tests.ps1') + (Join-Path -Path $PSScriptRoot -ChildPath 'Unit\Update-AllTheThings.Orchestration.Tests.ps1') + (Join-Path -Path $PSScriptRoot -ChildPath 'Unit\Update-AllTheThings.PackageManagers.Tests.ps1') + (Join-Path -Path $PSScriptRoot -ChildPath 'Unit\Update-AllTheThings.PowerShell.Tests.ps1') (Join-Path -Path $PSScriptRoot -ChildPath 'Unit\Update-AllTheThings.Helpers.Tests.ps1') (Join-Path -Path $PSScriptRoot -ChildPath 'Unit\Update-AllTheThings.Package.Tests.ps1') ) diff --git a/src/Tests/Unit/Update-AllTheThings.Cli.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Cli.Tests.ps1 index 3b14300e..81e3750f 100644 --- a/src/Tests/Unit/Update-AllTheThings.Cli.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Cli.Tests.ps1 @@ -4,11 +4,13 @@ BeforeDiscovery { Name = 'GitHub CLI extensions' CommandName = 'gh' UpdateCommand = 'Invoke-GitHubCliExtensionUpgrade' + UpdateScript = { Invoke-GitHubCliExtensionUpgrade } } @{ Name = 'GitHub Copilot CLI' CommandName = 'copilot' UpdateCommand = 'Invoke-GitHubCopilotCliUpdate' + UpdateScript = { Invoke-GitHubCopilotCliUpdate } } ) } @@ -20,17 +22,10 @@ BeforeAll { Describe 'Update-AllTheThings optional CLI updates' { BeforeEach { $script:AvailableCommands = @() - $script:SkipUnrelatedUpdates = @{ - SkipModules = $true - SkipScripts = $true - SkipHelp = $true - SkipWinGet = $true - } - Mock Get-PSPreworkoutPlatform { 'Unknown' } Mock Test-PSPreworkoutCommand { $Name -in $script:AvailableCommands } - Mock Write-Host - Mock Write-Progress + Mock Write-Information + Mock Write-UpdateAllTheThingsProgress Mock Write-Verbose Mock Invoke-GitHubCliExtensionUpgrade Mock Invoke-GitHubCopilotCliUpdate @@ -38,14 +33,26 @@ Describe 'Update-AllTheThings optional CLI updates' { It 'updates when is available' -ForEach $CliCases { $script:AvailableCommands = @($CommandName) + $UpdateParameters = @{ + CommandName = $CommandName + DisplayName = "Updating $Name" + CurrentOperation = "Updating $Name" + TargetName = $Name + ActionName = "Update $Name" + PercentComplete = 90 + UpdateCommand = $UpdateScript + Confirm = $false + } - Update-AllTheThings @script:SkipUnrelatedUpdates + Update-OptionalCli @UpdateParameters Should -Invoke -CommandName $UpdateCommand -Exactly 1 } It 'does not update when is unavailable' -ForEach $CliCases { - Update-AllTheThings @script:SkipUnrelatedUpdates + Update-OptionalCli -CommandName $CommandName -DisplayName "Updating $Name" ` + -CurrentOperation "Updating $Name" -TargetName $Name -ActionName "Update $Name" ` + -PercentComplete 90 -UpdateCommand $UpdateScript -Confirm:$false Should -Invoke -CommandName $UpdateCommand -Exactly 0 } @@ -53,7 +60,14 @@ Describe 'Update-AllTheThings optional CLI updates' { It 'does not run optional CLI updates during WhatIf' { $script:AvailableCommands = @('gh', 'copilot') - Update-AllTheThings @script:SkipUnrelatedUpdates -WhatIf + Update-OptionalCli -CommandName 'gh' -DisplayName 'Updating GitHub CLI extensions' ` + -CurrentOperation 'Updating GitHub CLI extensions' -TargetName 'GitHub CLI extensions' ` + -ActionName 'Update GitHub CLI extensions' -PercentComplete 90 ` + -UpdateCommand { Invoke-GitHubCliExtensionUpgrade } -WhatIf + Update-OptionalCli -CommandName 'copilot' -DisplayName 'Updating GitHub Copilot CLI' ` + -CurrentOperation 'Updating GitHub Copilot CLI' -TargetName 'GitHub Copilot CLI' ` + -ActionName 'Update GitHub Copilot CLI' -PercentComplete 95 ` + -UpdateCommand { Invoke-GitHubCopilotCliUpdate } -WhatIf Should -Invoke Invoke-GitHubCliExtensionUpgrade -Exactly 0 Should -Invoke Invoke-GitHubCopilotCliUpdate -Exactly 0 diff --git a/src/Tests/Unit/Update-AllTheThings.Helpers.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Helpers.Tests.ps1 index 43ba753f..e3c6b2cc 100644 --- a/src/Tests/Unit/Update-AllTheThings.Helpers.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Helpers.Tests.ps1 @@ -129,4 +129,56 @@ Describe 'Update-AllTheThings compatibility helpers' { { & $CommandName -Command { 23 } } | Should -Throw '*exit code 23*' } } + + Context 'Invoke-UpdateNativeCommand' { + It 'passes the command name and arguments to the invocation seam' { + $script:InvokedCommand = $null + $script:InvokedArguments = $null + $Command = { + param($CommandName, $CommandArguments) + + $script:InvokedCommand = $CommandName + $script:InvokedArguments = $CommandArguments + return 0 + } + + Invoke-UpdateNativeCommand -Name 'package-manager' -ArgumentList 'update', '-y' ` + -FailureMessage 'Package update' -Command $Command + + $script:InvokedCommand | Should -Be 'package-manager' + $script:InvokedArguments | Should -Be @('update', '-y') + } + + It 'throws with context when the native command fails' { + { + Invoke-UpdateNativeCommand -Name 'package-manager' -FailureMessage 'Package update' ` + -Command { 17 } + } | Should -Throw 'Package update failed with exit code 17.' + } + } + + Context 'Write-UpdateAllTheThingsProgress' { + BeforeEach { + Mock Write-Progress + } + + It 'writes a parent progress record' { + Write-UpdateAllTheThingsProgress -CurrentOperation 'Testing progress' -PercentComplete 42 + + Should -Invoke Write-Progress -Exactly 1 -ParameterFilter { + $Id -eq 0 -and + $Activity -eq 'Update Everything' -and + $CurrentOperation -eq 'Testing progress' -and + $PercentComplete -eq 42 + } + } + + It 'completes the parent progress record' { + Write-UpdateAllTheThingsProgress -Completed + + Should -Invoke Write-Progress -Exactly 1 -ParameterFilter { + $Id -eq 0 -and $Completed + } + } + } } diff --git a/src/Tests/Unit/Update-AllTheThings.Orchestration.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Orchestration.Tests.ps1 new file mode 100644 index 00000000..ac693e8f --- /dev/null +++ b/src/Tests/Unit/Update-AllTheThings.Orchestration.Tests.ps1 @@ -0,0 +1,82 @@ +BeforeDiscovery { + $PlatformCases = @( + @{ + Platform = 'Windows' + ExpectedCommand = 'Update-WinGetPackage' + } + @{ + Platform = 'Linux' + ExpectedCommand = 'Update-LinuxPackage' + } + @{ + Platform = 'macOS' + ExpectedCommand = 'Update-MacOSPackage' + } + ) +} + +BeforeAll { + . (Join-Path -Path $PSScriptRoot -ChildPath '..\Helpers\Update-AllTheThings.TestHelpers.ps1') +} + +Describe 'Update-AllTheThings orchestration' { + BeforeEach { + Mock Test-PSPreworkoutCommand { $false } + Mock Get-PSPreworkoutPlatform { 'Unknown' } + Mock Set-UpdateRepositoryTrust + Mock Update-PowerShellArtifact + Mock Update-WinGetPackage + Mock Update-LinuxPackage + Mock Update-MacOSPackage + Mock Update-OptionalCli + Mock Update-ChocolateyPackage + Mock Write-Host + Mock Write-Verbose + Mock Write-UpdateAllTheThingsProgress + } + + It 'runs the shared update stages once' { + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet + + Should -Invoke Set-UpdateRepositoryTrust -Exactly 1 + Should -Invoke Update-PowerShellArtifact -Exactly 1 -ParameterFilter { + $SkipModules -and $SkipScripts -and $SkipHelp + } + Should -Invoke Update-OptionalCli -Exactly 2 + Should -Invoke Update-ChocolateyPackage -Exactly 1 + } + + It 'runs only the platform updater' -ForEach $PlatformCases { + Mock Get-PSPreworkoutPlatform { $Platform } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -Confirm:$false + + Should -Invoke -CommandName $ExpectedCommand -Exactly 1 + Should -Invoke Update-WinGetPackage -Exactly ([int]($Platform -eq 'Windows')) + Should -Invoke Update-LinuxPackage -Exactly ([int]($Platform -eq 'Linux')) + Should -Invoke Update-MacOSPackage -Exactly ([int]($Platform -eq 'macOS')) + } + + It 'forwards package-manager options to their update stages' { + Mock Get-PSPreworkoutPlatform { 'Windows' } + + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet ` + -AcceptPrompts -IncludeChocolatey -Confirm:$false + + Should -Invoke Update-WinGetPackage -Exactly 1 -ParameterFilter { + $Skip -and $AcceptPrompts -and (-not $Confirm) + } + Should -Invoke Update-ChocolateyPackage -Exactly 1 -ParameterFilter { + $Include -and (-not $Confirm) + } + } + + It 'forwards WhatIf to update stages' { + Update-AllTheThings -SkipModules -SkipScripts -SkipHelp -SkipWinGet -WhatIf + + Should -Invoke Set-UpdateRepositoryTrust -Exactly 1 -ParameterFilter { $WhatIf } + Should -Invoke Update-PowerShellArtifact -Exactly 1 -ParameterFilter { $WhatIf } + Should -Invoke Update-OptionalCli -Exactly 2 -ParameterFilter { $WhatIf } + Should -Invoke Update-ChocolateyPackage -Exactly 1 -ParameterFilter { $WhatIf } + } +} diff --git a/src/Tests/Unit/Update-AllTheThings.PackageManagers.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.PackageManagers.Tests.ps1 new file mode 100644 index 00000000..4b917b68 --- /dev/null +++ b/src/Tests/Unit/Update-AllTheThings.PackageManagers.Tests.ps1 @@ -0,0 +1,100 @@ +BeforeAll { + . (Join-Path -Path $PSScriptRoot -ChildPath '..\Helpers\Update-AllTheThings.TestHelpers.ps1') +} + +Describe 'Update-AllTheThings package-manager helpers' { + BeforeEach { + $script:AvailableCommands = @() + + Mock Test-PSPreworkoutCommand { $Name -in $script:AvailableCommands } + Mock Test-IsElevated { $true } + Mock Invoke-UpdateNativeCommand + Mock Write-Information + Mock Write-Verbose + Mock Write-Warning + Mock Write-UpdateAllTheThingsProgress + } + + Context 'Linux package updates' { + It 'updates apt non-interactively without sudo when elevated' { + $script:AvailableCommands = @('apt') + + Update-LinuxPackage -AcceptPrompts -Confirm:$false + + Should -Invoke Invoke-UpdateNativeCommand -Exactly 1 -ParameterFilter { + $Name -eq 'apt' -and ($ArgumentList -join ' ') -eq 'update' + } + Should -Invoke Invoke-UpdateNativeCommand -Exactly 1 -ParameterFilter { + $Name -eq 'apt' -and ($ArgumentList -join ' ') -eq 'upgrade -y' + } + } + + It 'uses sudo for dnf when not elevated' { + $script:AvailableCommands = @('dnf') + Mock Test-IsElevated { $false } + + Update-LinuxPackage -Confirm:$false + + Should -Invoke Invoke-UpdateNativeCommand -Exactly 1 -ParameterFilter { + $Name -eq 'sudo' -and ($ArgumentList -join ' ') -eq 'dnf update' + } + } + + It 'does not invoke package managers during WhatIf' { + $script:AvailableCommands = @('apt', 'dnf') + + Update-LinuxPackage -WhatIf + + Should -Invoke Invoke-UpdateNativeCommand -Exactly 0 + } + + It 'does not inspect elevation when no supported package manager is installed' { + Update-LinuxPackage + + Should -Invoke Test-IsElevated -Exactly 0 + Should -Invoke Invoke-UpdateNativeCommand -Exactly 0 + } + } + + Context 'macOS package updates' { + It 'updates system software and Homebrew' { + $script:AvailableCommands = @('brew') + + Update-MacOSPackage -Confirm:$false + + Should -Invoke Invoke-UpdateNativeCommand -Exactly 1 -ParameterFilter { + $Name -eq 'softwareupdate' -and ($ArgumentList -join ' ') -eq '-l' + } + Should -Invoke Invoke-UpdateNativeCommand -Exactly 1 -ParameterFilter { + $Name -eq 'brew' -and ($ArgumentList -join ' ') -eq 'update' + } + Should -Invoke Invoke-UpdateNativeCommand -Exactly 1 -ParameterFilter { + $Name -eq 'brew' -and ($ArgumentList -join ' ') -eq 'upgrade' + } + } + } + + Context 'Chocolatey package updates' { + It 'updates Chocolatey features and packages when included and elevated' { + $script:AvailableCommands = @('choco') + + Update-ChocolateyPackage -Include -Confirm:$false + + Should -Invoke Invoke-UpdateNativeCommand -Exactly 4 + Should -Invoke Invoke-UpdateNativeCommand -Exactly 1 -ParameterFilter { + ($ArgumentList -join ' ') -eq 'upgrade chocolatey -y --limit-output --accept-license --no-color' + } + Should -Invoke Invoke-UpdateNativeCommand -Exactly 1 -ParameterFilter { + ($ArgumentList -join ' ') -eq 'upgrade all -y --limit-output --accept-license --no-color' + } + } + + It 'does not invoke Chocolatey when it is not included' { + $script:AvailableCommands = @('choco') + + Update-ChocolateyPackage + + Should -Invoke Invoke-UpdateNativeCommand -Exactly 0 + } + } +} diff --git a/src/Tests/Unit/Update-AllTheThings.PowerShell.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.PowerShell.Tests.ps1 new file mode 100644 index 00000000..3ec7d9fb --- /dev/null +++ b/src/Tests/Unit/Update-AllTheThings.PowerShell.Tests.ps1 @@ -0,0 +1,54 @@ +BeforeAll { + . (Join-Path -Path $PSScriptRoot -ChildPath '..\Helpers\Update-AllTheThings.TestHelpers.ps1') +} + +Describe 'Update-AllTheThings PowerShell updates' { + BeforeEach { + $script:AvailableCommands = @('Get-InstalledModule', 'Update-Script') + + Mock Test-PSPreworkoutCommand { $Name -in $script:AvailableCommands } + Mock Get-InstalledModule { + @( + [PSCustomObject]@{ Name = 'StableModule'; Version = [version]'1.2.3' } + [PSCustomObject]@{ Name = 'PreviewModule'; Version = '2.0.0-preview1' } + ) + } + Mock Update-Module + Mock Update-Script + Mock Update-Help + Mock Get-Culture { [cultureinfo]'en-US' } + Mock Write-Information + Mock Write-Warning + Mock Write-Verbose + Mock Write-Progress + Mock Write-UpdateAllTheThingsProgress + } + + It 'updates stable modules, scripts, and help' { + Update-PowerShellArtifact -Confirm:$false + + Should -Invoke Update-Module -Exactly 1 -ParameterFilter { $Name -eq 'StableModule' } + Should -Invoke Update-Module -Exactly 0 -ParameterFilter { $Name -eq 'PreviewModule' } + Should -Invoke Update-Script -Exactly 1 + Should -Invoke Update-Help -Exactly 1 + } + + It 'skips every PowerShell update when requested' { + Update-PowerShellArtifact -SkipModules -SkipScripts -SkipHelp + + Should -Invoke Get-InstalledModule -Exactly 0 + Should -Invoke Update-Module -Exactly 0 + Should -Invoke Update-Script -Exactly 0 + Should -Invoke Update-Help -Exactly 0 + } + + It 'skips unavailable module and script tooling with explicit warnings' { + $script:AvailableCommands = @() + + Update-PowerShellArtifact -SkipHelp + + Should -Invoke Write-Warning -Exactly 2 + Should -Invoke Update-Module -Exactly 0 + Should -Invoke Update-Script -Exactly 0 + } +} diff --git a/src/Tests/Unit/Update-AllTheThings.WinGet.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.WinGet.Tests.ps1 index 48ecfeff..83bd72c9 100644 --- a/src/Tests/Unit/Update-AllTheThings.WinGet.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.WinGet.Tests.ps1 @@ -25,25 +25,19 @@ BeforeAll { Describe 'Update-AllTheThings WinGet behavior' { BeforeEach { $script:AvailableCommands = @('winget') - $script:SkipUnrelatedUpdates = @{ - SkipModules = $true - SkipScripts = $true - SkipHelp = $true - } - Mock Get-PSPreworkoutPlatform { 'Windows' } Mock Test-PSPreworkoutCommand { $Name -in $script:AvailableCommands } Mock Get-WindowsOperatingSystemCaption { 'Windows Server 2025 Datacenter' } Mock Read-WinGetServerChoice { 0 } Mock Invoke-WinGetUpgrade - Mock Write-Host - Mock Write-Progress + Mock Write-Information + Mock Write-UpdateAllTheThingsProgress Mock Write-Verbose Mock Write-Warning } It 'updates packages when the Windows Server prompt is accepted' { - Update-AllTheThings @script:SkipUnrelatedUpdates + Update-WinGetPackage Should -Invoke Read-WinGetServerChoice -Exactly 1 Should -Invoke Invoke-WinGetUpgrade -Exactly 1 @@ -52,19 +46,19 @@ Describe 'Update-AllTheThings WinGet behavior' { It 'skips packages when the Windows Server prompt is declined' { Mock Read-WinGetServerChoice { 1 } - Update-AllTheThings @script:SkipUnrelatedUpdates + Update-WinGetPackage Should -Invoke Read-WinGetServerChoice -Exactly 1 Should -Invoke Invoke-WinGetUpgrade -Exactly 0 } It 'does not prompt with ' -ForEach $NonInteractiveConsentCases { - $Parameters = $script:SkipUnrelatedUpdates.Clone() + $Parameters = @{} foreach ($Entry in $Additional.GetEnumerator()) { $Parameters[$Entry.Key] = $Entry.Value } - Update-AllTheThings @Parameters + Update-WinGetPackage @Parameters Should -Invoke Read-WinGetServerChoice -Exactly 0 Should -Invoke Invoke-WinGetUpgrade -Exactly $ExpectedUpdates @@ -73,7 +67,7 @@ Describe 'Update-AllTheThings WinGet behavior' { It 'does not prompt on a Windows client' { Mock Get-WindowsOperatingSystemCaption { 'Microsoft Windows 11 Pro' } - Update-AllTheThings @script:SkipUnrelatedUpdates + Update-WinGetPackage Should -Invoke Read-WinGetServerChoice -Exactly 0 Should -Invoke Invoke-WinGetUpgrade -Exactly 1 @@ -82,7 +76,7 @@ Describe 'Update-AllTheThings WinGet behavior' { It 'fails closed when the Windows caption cannot be determined' { Mock Get-WindowsOperatingSystemCaption - Update-AllTheThings @script:SkipUnrelatedUpdates + Update-WinGetPackage Should -Invoke Write-Warning -Exactly 1 -ParameterFilter { $Message -match 'Unable to determine the Windows operating system caption' @@ -91,26 +85,17 @@ Describe 'Update-AllTheThings WinGet behavior' { } It 'does not inspect Windows when WinGet is skipped explicitly' { - Update-AllTheThings @script:SkipUnrelatedUpdates -SkipWinGet + Update-WinGetPackage -Skip Should -Invoke Get-WindowsOperatingSystemCaption -Exactly 0 Should -Invoke Read-WinGetServerChoice -Exactly 0 Should -Invoke Invoke-WinGetUpgrade -Exactly 0 } - It 'does not inspect or update WinGet on a non-Windows platform' { - Mock Get-PSPreworkoutPlatform { 'Linux' } - - Update-AllTheThings @script:SkipUnrelatedUpdates - - Should -Invoke Get-WindowsOperatingSystemCaption -Exactly 0 - Should -Invoke Invoke-WinGetUpgrade -Exactly 0 - } - It 'skips WinGet when the command is unavailable' { $script:AvailableCommands = @() - Update-AllTheThings @script:SkipUnrelatedUpdates + Update-WinGetPackage Should -Invoke Get-WindowsOperatingSystemCaption -Exactly 0 Should -Invoke Invoke-WinGetUpgrade -Exactly 0 From 77912a574fc3c5425f8a3cd9fd9e0f52a9593240 Mon Sep 17 00:00:00 2001 From: Sam Erde <20478745+SamErde@users.noreply.github.com> Date: Mon, 14 Sep 2026 10:18:29 -0400 Subject: [PATCH 29/30] =?UTF-8?q?=F0=9F=90=9B=20fix(build):=20honor=20gene?= =?UTF-8?q?rated=20script=20line=20endings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Emit deterministic CRLF output to match the repository PowerShell line-ending policy and keep byte-parity checks stable across CI hosts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- Scripts/Update-AllTheThings_Build.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Scripts/Update-AllTheThings_Build.ps1 b/Scripts/Update-AllTheThings_Build.ps1 index ce9faee5..f724d2b9 100644 --- a/Scripts/Update-AllTheThings_Build.ps1 +++ b/Scripts/Update-AllTheThings_Build.ps1 @@ -63,7 +63,7 @@ $SourcePaths = @( $ScriptInfoContent = Get-Content -LiteralPath $ScriptInfoPath -Raw $UpdateCommandContent = Get-Content -LiteralPath $UpdateCommandPath -Raw -$LineFeed = [string][char]10 +$NewLine = [string][char]13 + [string][char]10 $SemVerPattern = 'v(\d+)\.(\d+)\.(\d+)' $SemVerMatch = [regex]::Match($UpdateCommandContent, $SemVerPattern) @@ -104,17 +104,17 @@ $ScriptInfoContent = [regex]::Replace( ) $UpdateCommandContent = $UpdateCommandContent.Replace($SemVerMatch.Value, "v$NewVersion") -$GeneratedParts = @(($ScriptInfoContent -replace "`r`n?", $LineFeed).TrimEnd()) +$GeneratedParts = @(($ScriptInfoContent -replace "`r`n?|\n", $NewLine).TrimEnd()) foreach ($SourcePath in $SourcePaths) { if ($SourcePath -eq $UpdateCommandPath) { - $GeneratedParts += ($UpdateCommandContent -replace "`r`n?", $LineFeed).TrimEnd() + $GeneratedParts += ($UpdateCommandContent -replace "`r`n?|\n", $NewLine).TrimEnd() } else { $SourceContent = Get-Content -LiteralPath $SourcePath -Raw - $GeneratedParts += ($SourceContent -replace "`r`n?", $LineFeed).TrimEnd() + $GeneratedParts += ($SourceContent -replace "`r`n?|\n", $NewLine).TrimEnd() } } -$GeneratedContent = ($GeneratedParts -join ($LineFeed + $LineFeed)) + $LineFeed +$GeneratedContent = ($GeneratedParts -join ($NewLine + $NewLine)) + $NewLine $Utf8NoBom = [System.Text.UTF8Encoding]::new($false) [System.IO.File]::WriteAllText($OutputPath, $GeneratedContent, $Utf8NoBom) From 96928729f6b32bbfcea063c8072d6226c5d1d195 Mon Sep 17 00:00:00 2001 From: Sam Erde <20478745+SamErde@users.noreply.github.com> Date: Mon, 14 Sep 2026 10:22:49 -0400 Subject: [PATCH 30/30] =?UTF-8?q?=F0=9F=90=9B=20fix(build):=20document=20d?= =?UTF-8?q?elegated=20ShouldProcess?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suppress the analyzer false positive on the public orchestrator because confirmation is forwarded to private helpers, and cover the contract in Pester. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- Scripts/Update-AllTheThings.ps1 | 1 + src/PSPreworkout/Public/Update-AllTheThings.ps1 | 1 + src/Tests/Unit/Update-AllTheThings.Contract.Tests.ps1 | 1 + 3 files changed, 3 insertions(+) diff --git a/Scripts/Update-AllTheThings.ps1 b/Scripts/Update-AllTheThings.ps1 index fc62d769..b2490f8a 100644 --- a/Scripts/Update-AllTheThings.ps1 +++ b/Scripts/Update-AllTheThings.ps1 @@ -949,6 +949,7 @@ function Update-AllTheThings { )] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'This is what we do.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Interactive Use')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '', Justification = 'WhatIf and Confirm are forwarded to private helpers that call ShouldProcess.')] [Alias('uatt')] param ( # Skip the step that updates PowerShell modules diff --git a/src/PSPreworkout/Public/Update-AllTheThings.ps1 b/src/PSPreworkout/Public/Update-AllTheThings.ps1 index 210636e0..067986fd 100644 --- a/src/PSPreworkout/Public/Update-AllTheThings.ps1 +++ b/src/PSPreworkout/Public/Update-AllTheThings.ps1 @@ -46,6 +46,7 @@ function Update-AllTheThings { )] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'This is what we do.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Interactive Use')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '', Justification = 'WhatIf and Confirm are forwarded to private helpers that call ShouldProcess.')] [Alias('uatt')] param ( # Skip the step that updates PowerShell modules diff --git a/src/Tests/Unit/Update-AllTheThings.Contract.Tests.ps1 b/src/Tests/Unit/Update-AllTheThings.Contract.Tests.ps1 index f75cbab6..18fbc448 100644 --- a/src/Tests/Unit/Update-AllTheThings.Contract.Tests.ps1 +++ b/src/Tests/Unit/Update-AllTheThings.Contract.Tests.ps1 @@ -11,6 +11,7 @@ BeforeDiscovery { $SuppressionCases = @( @{ Category = 'PSUseSingularNouns' } @{ Category = 'PSAvoidUsingWriteHost' } + @{ Category = 'PSShouldProcess' } ) } BeforeAll {