From 4fc9d22749d885706bfcb15a5a268b1745a8b710 Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Fri, 29 Jul 2022 13:54:56 +0200 Subject: [PATCH 01/17] Keeping critical files... --- Winget-AutoUpdate-Install.ps1 | 10 +++++----- Winget-AutoUpdate/WAU-Uninstall.ps1 | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 794c6d7..d36f387 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -171,18 +171,18 @@ function Install-WingetAutoUpdate { Write-Host "`nInstalling WAU..." -ForegroundColor Yellow try { - #Copy files to location (and clean old install) + #Copy files to location (and clean old install, keeping critical files) if (!(Test-Path $WingetUpdatePath)) { New-Item -ItemType Directory -Force -Path $WingetUpdatePath | Out-Null } else { - Remove-Item -Path "$WingetUpdatePath\*" -Exclude *.log -Recurse -Force + Get-ChildItem -Path $WingetUpdatePath -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force } Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue #White List or Black List apps if ($UseWhiteList) { - if (Test-Path "$PSScriptRoot\included_apps.txt") { + if ((Test-Path "$PSScriptRoot\included_apps.txt") -and !(Test-Path "$WingetUpdatePath\included_apps.txt")) { Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue } else { @@ -280,9 +280,9 @@ function Uninstall-WingetAutoUpdate { #Get registry install location $InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation - #Check if installed location exists and delete + #Check if installed location exists and delete, keeping critical files if (Test-Path ($InstallLocation)) { - Remove-Item $InstallLocation -Force -Recurse + Get-ChildItem -Path $InstallLocation -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False & reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null diff --git a/Winget-AutoUpdate/WAU-Uninstall.ps1 b/Winget-AutoUpdate/WAU-Uninstall.ps1 index 3701b1f..ef239cd 100644 --- a/Winget-AutoUpdate/WAU-Uninstall.ps1 +++ b/Winget-AutoUpdate/WAU-Uninstall.ps1 @@ -16,9 +16,9 @@ try { #Get registry install location $InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation - #Check if installed location exists and delete + #Check if installed location exists and delete, keeping critical files if (Test-Path ($InstallLocation)) { - Remove-Item "$InstallLocation\*" -Force -Recurse -Exclude "*.log" + Get-ChildItem -Path $InstallLocation -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False & reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null From 03be2cde028bd746f244d4718b8f4360e3478de2 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 30 Jul 2022 03:48:37 +0200 Subject: [PATCH 02/17] Test-PendingReboot --- .../functions/Test-PendingReboot.ps1 | 31 +++++++++++++++++++ Winget-AutoUpdate/functions/Update-App.ps1 | 26 ++++++++++------ 2 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 Winget-AutoUpdate/functions/Test-PendingReboot.ps1 diff --git a/Winget-AutoUpdate/functions/Test-PendingReboot.ps1 b/Winget-AutoUpdate/functions/Test-PendingReboot.ps1 new file mode 100644 index 0000000..023ab4c --- /dev/null +++ b/Winget-AutoUpdate/functions/Test-PendingReboot.ps1 @@ -0,0 +1,31 @@ +#Function to check if there's a Pending Reboot + +function Test-PendingReboot { + + $Computer = $env:COMPUTERNAME + $PendingReboot = $false + + $HKLM = [UInt32] "0x80000002" + $WMI_Reg = [WMIClass] "\\$Computer\root\default:StdRegProv" + + if ($WMI_Reg) { + if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")).sNames -contains 'RebootPending') {$PendingReboot = $true} + if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")).sNames -contains 'RebootRequired') {$PendingReboot = $true} + + #Checking for SCCM namespace + $SCCM_Namespace = Get-WmiObject -Namespace ROOT\CCM\ClientSDK -List -ComputerName $Computer -ErrorAction Ignore + if ($SCCM_Namespace) { + if (([WmiClass]"\\$Computer\ROOT\CCM\ClientSDK:CCM_ClientUtilities").DetermineIfRebootPending().RebootPending -eq $true) {$PendingReboot = $true} + } + + # [PSCustomObject]@{ + # ComputerName = $Computer.ToUpper() + # PendingReboot = $PendingReboot + # } + } + $null = $WMI_Reg + $null = $SCCM_Namespace + + return $PendingReboot + +} \ No newline at end of file diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 55cdefb..ae1f251 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -28,17 +28,25 @@ Function Update-App ($app) { foreach ($CheckApp in $CheckOutdated) { if ($($CheckApp.Id) -eq $($app.Id)) { - #If app failed to upgrade, run Install command - & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append + #Upgrade failed for a reason? Check for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) + $PendingReboot = Test-PendingReboot + if ($PendingReboot) { + $FailedToUpgrade = $true + Write-Log "A Pending Reboot prohibited $($app.Id) from upgrading..." "Red" + } + else { + #If app failed to upgrade, run Install command + & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append - #Set mods to apply as an install - $ModsMode = "Install" + #Set mods to apply as an install + $ModsMode = "Install" - #Check if application installed properly - $CheckOutdated2 = Get-WingetOutdatedApps - foreach ($CheckApp2 in $CheckOutdated2) { - if ($($CheckApp2.Id) -eq $($app.Id)) { - $FailedToUpgrade = $true + #Check if application installed properly + $CheckOutdated2 = Get-WingetOutdatedApps + foreach ($CheckApp2 in $CheckOutdated2) { + if ($($CheckApp2.Id) -eq $($app.Id)) { + $FailedToUpgrade = $true + } } } } From f7d7bc1d3ed915fa40520e7676f95f670940b3ab Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 30 Jul 2022 03:54:39 +0200 Subject: [PATCH 03/17] if ($PendingReboot -eq $true) --- Winget-AutoUpdate/functions/Update-App.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index ae1f251..d8e0ed3 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -30,7 +30,7 @@ Function Update-App ($app) { #Upgrade failed for a reason? Check for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) $PendingReboot = Test-PendingReboot - if ($PendingReboot) { + if ($PendingReboot -eq $true) { $FailedToUpgrade = $true Write-Log "A Pending Reboot prohibited $($app.Id) from upgrading..." "Red" } From 3519854f310c4679aaaec6a5cbf4cb0cfba4fe4d Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 30 Jul 2022 09:31:05 +0200 Subject: [PATCH 04/17] PARAMETER NoClean --- Winget-AutoUpdate-Install.ps1 | 28 +++++++++++++++++++++---- Winget-AutoUpdate/WAU-Uninstall.ps1 | 32 +++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index d36f387..4749d43 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -25,6 +25,9 @@ Use White List instead of Black List. This setting will not create the "exclude_ .PARAMETER Uninstall Remove scheduled tasks and scripts. +.PARAMETER NoClean +Keep critical files when uninstalling + .PARAMETER NotificationLevel Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). @@ -46,6 +49,9 @@ Run WAU on metered connection. Default No. .EXAMPLE .\winget-install-and-update.ps1 -Silent -UpdatesAtLogon -UpdatesInterval Weekly +.EXAMPLE +.\WAU-Uninstall.ps1 -Silent -Uninstall -NoClean + #> [CmdletBinding()] @@ -56,6 +62,7 @@ param( [Parameter(Mandatory = $False)] [Switch] $DisableWAUAutoUpdate = $false, [Parameter(Mandatory = $False)] [Switch] $RunOnMetered = $false, [Parameter(Mandatory = $False)] [Switch] $Uninstall = $false, + [Parameter(Mandatory = $False)] [Switch] $NoClean = $false, [Parameter(Mandatory = $False)] [Switch] $UseWhiteList = $false, [Parameter(Mandatory = $False)] [ValidateSet("Full", "SuccessOnly", "None")] [String] $NotificationLevel = "Full", [Parameter(Mandatory = $False)] [Switch] $UpdatesAtLogon = $false, @@ -171,12 +178,18 @@ function Install-WingetAutoUpdate { Write-Host "`nInstalling WAU..." -ForegroundColor Yellow try { - #Copy files to location (and clean old install, keeping critical files) + #Copy files to location (and clean old install) if (!(Test-Path $WingetUpdatePath)) { New-Item -ItemType Directory -Force -Path $WingetUpdatePath | Out-Null } else { - Get-ChildItem -Path $WingetUpdatePath -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force + if (!$NoClean) { + Remove-Item "$WingetUpdatePath\*" -Force -Recurse -Exclude "*.log" + } + else { + #Keep critical files + Get-ChildItem -Path $WingetUpdatePath -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force + } } Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue @@ -280,9 +293,16 @@ function Uninstall-WingetAutoUpdate { #Get registry install location $InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation - #Check if installed location exists and delete, keeping critical files + #Check if installed location exists and delete if (Test-Path ($InstallLocation)) { - Get-ChildItem -Path $InstallLocation -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force + + if (!$NoClean) { + Remove-Item "$InstallLocation\*" -Force -Recurse -Exclude "*.log" + } + else { + #Keep critical files + Get-ChildItem -Path $InstallLocation -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force + } Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False & reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null diff --git a/Winget-AutoUpdate/WAU-Uninstall.ps1 b/Winget-AutoUpdate/WAU-Uninstall.ps1 index ef239cd..f9954b5 100644 --- a/Winget-AutoUpdate/WAU-Uninstall.ps1 +++ b/Winget-AutoUpdate/WAU-Uninstall.ps1 @@ -1,3 +1,24 @@ +<# +.SYNOPSIS +Uninstall Winget-AutoUpdate + +.DESCRIPTION +Uninstall Winget-AutoUpdate (DEFAULT: clean old install) +https://github.com/Romanitho/Winget-AutoUpdate + +.PARAMETER NoClean +Uninstall Winget-AutoUpdate (keep critical files) + +.EXAMPLE +.\WAU-Uninstall.ps1 -NoClean + +#> + +[CmdletBinding()] +param( + [Parameter(Mandatory = $False)] [Switch] $NoClean = $false +) + Write-Host "`n" Write-Host "`t 888 888 d8888 888 888" -ForegroundColor Magenta Write-Host "`t 888 o 888 d88888 888 888" -ForegroundColor Magenta @@ -16,9 +37,16 @@ try { #Get registry install location $InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation - #Check if installed location exists and delete, keeping critical files + #Check if installed location exists and delete if (Test-Path ($InstallLocation)) { - Get-ChildItem -Path $InstallLocation -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force + + if (!$NoClean) { + Remove-Item "$InstallLocation\*" -Force -Recurse -Exclude "*.log" + } + else { + #Keep critical files + Get-ChildItem -Path $InstallLocation -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force + } Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False & reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null From a46583518274d62751c122ea817bb28916553949 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 30 Jul 2022 09:34:10 +0200 Subject: [PATCH 05/17] Wrong file name in example --- Winget-AutoUpdate-Install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 4749d43..90d8361 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -50,7 +50,7 @@ Run WAU on metered connection. Default No. .\winget-install-and-update.ps1 -Silent -UpdatesAtLogon -UpdatesInterval Weekly .EXAMPLE -.\WAU-Uninstall.ps1 -Silent -Uninstall -NoClean +.\Winget-AutoUpdate-Install.ps1 -Silent -Uninstall -NoClean #> From 4d3e086b7e160ba3b34414b49f2d404909e380cf Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 30 Jul 2022 09:41:03 +0200 Subject: [PATCH 06/17] Description of PARAMETER NoClean corrected --- Winget-AutoUpdate-Install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 90d8361..b4ead89 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -26,7 +26,7 @@ Use White List instead of Black List. This setting will not create the "exclude_ Remove scheduled tasks and scripts. .PARAMETER NoClean -Keep critical files when uninstalling +Keep critical files when installing/uninstalling .PARAMETER NotificationLevel Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). From 26f078f8ee437e52c999c311fc8268c55f065ee8 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 30 Jul 2022 15:10:41 +0200 Subject: [PATCH 07/17] Fixes for $NoClean and $PendingReboot --- Winget-AutoUpdate-Install.ps1 | 8 +++++--- Winget-AutoUpdate/WAU-Uninstall.ps1 | 2 +- Winget-AutoUpdate/functions/Test-PendingReboot.ps1 | 4 +--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index b4ead89..2f82626 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -188,7 +188,7 @@ function Install-WingetAutoUpdate { } else { #Keep critical files - Get-ChildItem -Path $WingetUpdatePath -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force + Get-ChildItem -Path $WingetUpdatePath -Exclude *.txt,mods,logs | Remove-Item -Recurse -Force } } Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue @@ -203,7 +203,9 @@ function Install-WingetAutoUpdate { } } else { - Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue + if (!$NoClean) { + Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue + } } # Set dummy regkeys for notification name and icon @@ -301,7 +303,7 @@ function Uninstall-WingetAutoUpdate { } else { #Keep critical files - Get-ChildItem -Path $InstallLocation -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force + Get-ChildItem -Path $InstallLocation -Exclude *.txt,mods,logs | Remove-Item -Recurse -Force } Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False diff --git a/Winget-AutoUpdate/WAU-Uninstall.ps1 b/Winget-AutoUpdate/WAU-Uninstall.ps1 index f9954b5..9ce09c7 100644 --- a/Winget-AutoUpdate/WAU-Uninstall.ps1 +++ b/Winget-AutoUpdate/WAU-Uninstall.ps1 @@ -45,7 +45,7 @@ try { } else { #Keep critical files - Get-ChildItem -Path $InstallLocation -Exclude included_apps.txt,mods,logs | Remove-Item -Recurse -Force + Get-ChildItem -Path $InstallLocation -Exclude *.txt,mods,logs | Remove-Item -Recurse -Force } Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False diff --git a/Winget-AutoUpdate/functions/Test-PendingReboot.ps1 b/Winget-AutoUpdate/functions/Test-PendingReboot.ps1 index 023ab4c..795be9c 100644 --- a/Winget-AutoUpdate/functions/Test-PendingReboot.ps1 +++ b/Winget-AutoUpdate/functions/Test-PendingReboot.ps1 @@ -23,9 +23,7 @@ function Test-PendingReboot { # PendingReboot = $PendingReboot # } } - $null = $WMI_Reg - $null = $SCCM_Namespace return $PendingReboot -} \ No newline at end of file +} From 687a24bafddac574acaae5e1917c09b8b0863264 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 30 Jul 2022 15:22:34 +0200 Subject: [PATCH 08/17] Back with original total uninstall --- Winget-AutoUpdate-Install.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 2f82626..7e866b3 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -184,7 +184,7 @@ function Install-WingetAutoUpdate { } else { if (!$NoClean) { - Remove-Item "$WingetUpdatePath\*" -Force -Recurse -Exclude "*.log" + Remove-Item -Path "$WingetUpdatePath\*" -Exclude *.log -Recurse -Force } else { #Keep critical files @@ -299,7 +299,7 @@ function Uninstall-WingetAutoUpdate { if (Test-Path ($InstallLocation)) { if (!$NoClean) { - Remove-Item "$InstallLocation\*" -Force -Recurse -Exclude "*.log" + Remove-Item $InstallLocation -Force -Recurse } else { #Keep critical files From d6ea9b9e673cf1256be904f5ec64c18961b28ec3 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 30 Jul 2022 15:43:45 +0200 Subject: [PATCH 09/17] Fix for WhiteList NoClean --- Winget-AutoUpdate-Install.ps1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 7e866b3..312b519 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -195,10 +195,15 @@ function Install-WingetAutoUpdate { #White List or Black List apps if ($UseWhiteList) { - if ((Test-Path "$PSScriptRoot\included_apps.txt") -and !(Test-Path "$WingetUpdatePath\included_apps.txt")) { - Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue + if (!$NoClean) { + if ((Test-Path "$PSScriptRoot\included_apps.txt")) { + Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue + } + else { + New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null + } } - else { + elseif (!(Test-Path "$WingetUpdatePath\included_apps.txt")) { New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null } } From 2b6e92bc72148bce6c444081ca376d4c50d6721e Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 31 Jul 2022 11:29:39 +0200 Subject: [PATCH 10/17] Better log description of Pending Reboot --- Winget-AutoUpdate/functions/Update-App.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index d8e0ed3..8db4f58 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -32,7 +32,7 @@ Function Update-App ($app) { $PendingReboot = Test-PendingReboot if ($PendingReboot -eq $true) { $FailedToUpgrade = $true - Write-Log "A Pending Reboot prohibited $($app.Id) from upgrading..." "Red" + Write-Log "A Pending Reboot probably prohibited $($app.Id) from upgrading..." "Red" } else { #If app failed to upgrade, run Install command From 638ab63164cde37a7056b205041397d3356fc9b0 Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Mon, 1 Aug 2022 08:44:20 +0200 Subject: [PATCH 11/17] Test Pendig Reboot first (for every upgrade)... --- Winget-AutoUpdate/functions/Update-App.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 8db4f58..f4e68e8 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -16,6 +16,12 @@ Function Update-App ($app) { #Winget upgrade Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" + #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) + $PendingReboot = Test-PendingReboot + if ($PendingReboot -eq $true) { + Write-Log "A Pending Reboot exists and can prohibit ugrades/installs..." "Yellow" + } + #Run Winget Upgrade command & $Winget upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append @@ -28,8 +34,7 @@ Function Update-App ($app) { foreach ($CheckApp in $CheckOutdated) { if ($($CheckApp.Id) -eq $($app.Id)) { - #Upgrade failed for a reason? Check for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) - $PendingReboot = Test-PendingReboot + #Upgrade failed for a reason? if ($PendingReboot -eq $true) { $FailedToUpgrade = $true Write-Log "A Pending Reboot probably prohibited $($app.Id) from upgrading..." "Red" From 102799676ae6aeead37b7fdb6af5fb625c3daed7 Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Mon, 1 Aug 2022 09:10:44 +0200 Subject: [PATCH 12/17] Fixing the loop, more info --- Winget-AutoUpdate/functions/Update-App.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index f4e68e8..8020b2d 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -36,10 +36,8 @@ Function Update-App ($app) { #Upgrade failed for a reason? if ($PendingReboot -eq $true) { - $FailedToUpgrade = $true - Write-Log "A Pending Reboot probably prohibited $($app.Id) from upgrading..." "Red" + Write-Log "A Pending Reboot probably prohibited $($app.Id) from upgrading, now trying an install..." "Red" } - else { #If app failed to upgrade, run Install command & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append @@ -50,10 +48,13 @@ Function Update-App ($app) { $CheckOutdated2 = Get-WingetOutdatedApps foreach ($CheckApp2 in $CheckOutdated2) { if ($($CheckApp2.Id) -eq $($app.Id)) { + #Upgrade failed for a reason? + if ($PendingReboot -eq $true) { + Write-Log "...a Pending Reboot probably prohibited $($app.Id) from installing too..." "Red" + } $FailedToUpgrade = $true } } - } } } From b4825030086ae8967f6796ca2a4b7eb5cc2c3a00 Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Mon, 1 Aug 2022 10:41:36 +0200 Subject: [PATCH 13/17] Don't test for pending reboot until fail --- Winget-AutoUpdate/functions/Update-App.ps1 | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 8020b2d..639c546 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -16,12 +16,6 @@ Function Update-App ($app) { #Winget upgrade Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" - #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) - $PendingReboot = Test-PendingReboot - if ($PendingReboot -eq $true) { - Write-Log "A Pending Reboot exists and can prohibit ugrades/installs..." "Yellow" - } - #Run Winget Upgrade command & $Winget upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append @@ -34,7 +28,8 @@ Function Update-App ($app) { foreach ($CheckApp in $CheckOutdated) { if ($($CheckApp.Id) -eq $($app.Id)) { - #Upgrade failed for a reason? + #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) + $PendingReboot = Test-PendingReboot if ($PendingReboot -eq $true) { Write-Log "A Pending Reboot probably prohibited $($app.Id) from upgrading, now trying an install..." "Red" } @@ -48,9 +43,9 @@ Function Update-App ($app) { $CheckOutdated2 = Get-WingetOutdatedApps foreach ($CheckApp2 in $CheckOutdated2) { if ($($CheckApp2.Id) -eq $($app.Id)) { - #Upgrade failed for a reason? + #If app failed to install if ($PendingReboot -eq $true) { - Write-Log "...a Pending Reboot probably prohibited $($app.Id) from installing too..." "Red" + Write-Log "...a Pending Reboot probably prohibited $($app.Id) also from installing..." "Red" } $FailedToUpgrade = $true } From da5d9aa0837a9bfbf90e2cd01d21208a6e916f7e Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Mon, 1 Aug 2022 13:25:14 +0200 Subject: [PATCH 14/17] Test Pending Reboot corect now (before upgrades --- Winget-AutoUpdate/functions/Update-App.ps1 | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 639c546..10c009b 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -16,6 +16,9 @@ Function Update-App ($app) { #Winget upgrade Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" + #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) + $PendingReboot = Test-PendingReboot + #Run Winget Upgrade command & $Winget upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append @@ -28,28 +31,20 @@ Function Update-App ($app) { foreach ($CheckApp in $CheckOutdated) { if ($($CheckApp.Id) -eq $($app.Id)) { - #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) - $PendingReboot = Test-PendingReboot - if ($PendingReboot -eq $true) { - Write-Log "A Pending Reboot probably prohibited $($app.Id) from upgrading, now trying an install..." "Red" - } - #If app failed to upgrade, run Install command - & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append + #If app failed to upgrade, run Install command + & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append - #Set mods to apply as an install - $ModsMode = "Install" + #Set mods to apply as an install + $ModsMode = "Install" - #Check if application installed properly - $CheckOutdated2 = Get-WingetOutdatedApps - foreach ($CheckApp2 in $CheckOutdated2) { - if ($($CheckApp2.Id) -eq $($app.Id)) { - #If app failed to install - if ($PendingReboot -eq $true) { - Write-Log "...a Pending Reboot probably prohibited $($app.Id) also from installing..." "Red" - } - $FailedToUpgrade = $true - } + #Check if application installed properly + $CheckOutdated2 = Get-WingetOutdatedApps + foreach ($CheckApp2 in $CheckOutdated2) { + if ($($CheckApp2.Id) -eq $($app.Id)) { + #If app failed to install + $FailedToUpgrade = $true } + } } } @@ -88,6 +83,10 @@ Function Update-App ($app) { } else { + if ($PendingReboot -eq $true) { + Write-Log "A Pending Reboot probably prohibited $($app.Id) from upgrading..." "Red" + } + #Send failed updated app notification Write-Log "$($app.Name) update failed." "Red" From 5f852d986dc75fe98e3aa0288e3a8dfe65acb11f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 4 Aug 2022 22:04:06 +0200 Subject: [PATCH 15/17] Only test PendingReboot if upgrade fails! Break. --- Winget-AutoUpdate/functions/Update-App.ps1 | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 10c009b..bd1eea0 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -16,9 +16,6 @@ Function Update-App ($app) { #Winget upgrade Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" - #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) - $PendingReboot = Test-PendingReboot - #Run Winget Upgrade command & $Winget upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append @@ -31,7 +28,18 @@ Function Update-App ($app) { foreach ($CheckApp in $CheckOutdated) { if ($($CheckApp.Id) -eq $($app.Id)) { + #Upgrade failed! + #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) + $PendingReboot = Test-PendingReboot + if ($PendingReboot -eq $true) { + Write-Log "A Pending Reboot lingers and probably prohibited $($app.Id) from upgrading..." "Red" + Write-Log "...an install for $($app.Id) is NOT executed!" "Red" + $FailedToUpgrade = $true + break + } + #If app failed to upgrade, run Install command + Write-Log "An upgrade for $($app.Id) failed, now trying an install..." "Yellow" & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append #Set mods to apply as an install @@ -41,7 +49,6 @@ Function Update-App ($app) { $CheckOutdated2 = Get-WingetOutdatedApps foreach ($CheckApp2 in $CheckOutdated2) { if ($($CheckApp2.Id) -eq $($app.Id)) { - #If app failed to install $FailedToUpgrade = $true } } @@ -83,10 +90,6 @@ Function Update-App ($app) { } else { - if ($PendingReboot -eq $true) { - Write-Log "A Pending Reboot probably prohibited $($app.Id) from upgrading..." "Red" - } - #Send failed updated app notification Write-Log "$($app.Name) update failed." "Red" From 6b961ce22e6204e4f59e9265ca703db4189c205f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 4 Aug 2022 22:12:43 +0200 Subject: [PATCH 16/17] Name instead of ID... --- Winget-AutoUpdate/functions/Update-App.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index bd1eea0..4a9c769 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -32,14 +32,14 @@ Function Update-App ($app) { #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) $PendingReboot = Test-PendingReboot if ($PendingReboot -eq $true) { - Write-Log "A Pending Reboot lingers and probably prohibited $($app.Id) from upgrading..." "Red" - Write-Log "...an install for $($app.Id) is NOT executed!" "Red" + Write-Log "A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading..." "Red" + Write-Log "...an install for $($app.Name) is NOT executed!" "Red" $FailedToUpgrade = $true break } #If app failed to upgrade, run Install command - Write-Log "An upgrade for $($app.Id) failed, now trying an install..." "Yellow" + Write-Log "An upgrade for $($app.Name) failed, now trying an install..." "Yellow" & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append #Set mods to apply as an install From deb686d6ae8381095cc9db1a294e8216069ae397 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 7 Aug 2022 09:32:25 +0200 Subject: [PATCH 17/17] Less Write-Log --- Winget-AutoUpdate/functions/Update-App.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 4a9c769..2fda09e 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -32,8 +32,7 @@ Function Update-App ($app) { #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) $PendingReboot = Test-PendingReboot if ($PendingReboot -eq $true) { - Write-Log "A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading..." "Red" - Write-Log "...an install for $($app.Name) is NOT executed!" "Red" + Write-Log "A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading...`n...an install for $($app.Name) is NOT executed!" "Red" $FailedToUpgrade = $true break }